Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Search's search.in doesn't return results when using spaces

I'm calling Azure Search from my c# application.

When I'm trying to filter on the categories of my products it only gives me results when the category doesn't contain any spaces.

search.in(ProductCategory,'Garden')  // Works
search.in(ProductCategory,'Sport and Games')  // Doesn't Work
search.in(ProductCategory,'Garden, Sport and Games')  // Only shows 'Garden' results

The documentation shows that spaces can be used so I'm wondering why I'm not getting any results when I'm using spaces.

$filter=search.in(name, 'Roach motel, Budget hotel') // Sample from docs

It also states that search.in(field, 'one,two,three') is equal to field eq 'one' or field eq 'two' or field eq 'three'. But when I use this in my case, so ProductCategory eq 'Sport and Games' it works.

So I think there is some sort of difference between them. But I can't figure out what it is. I first thought it might has something to do with the field ProductCategory not being searchable but on the other hand, it works with non-space categories. Also if it acts like an eg then it's a filter not a search, right..?

Can anybody explain the difference?


For now I'm just creating the filter without the search and just the ProductCategory eq 'Sport and Games or ...' but this can become very long when someone selects a lot of categories.

like image 595
SEG.Veenstra Avatar asked Jan 09 '18 07:01

SEG.Veenstra


People also ask

How to work with search results in azure Cognitive Search?

How to work with search results in Azure Cognitive Search 1 Paging results. By default, the search engine returns up to the first 50 matches, as determined by search score if the query is full text search, or in an arbitrary ... 2 Ordering results. ... 3 Hit highlighting. ... 4 Next steps. ...

How do I get total hits in Azure Search?

In Azure Search, you use the $count, $top, and $skip parameters to return these values. The following example shows a sample request for total hits on an index called "online-catalog", returned as @odata.count: Retrieve documents in groups of 15, and also show the total hits, starting at the first page:

How do I limit the number of searchable fields per search field?

Each additional searchable field results in more work for the search service. You can limit the fields being searched at query time using the "searchFields" parameter. It's best to specify only the fields that you care about to improve performance. Amount of data being returned. Retrieving a large amount content can make queries slower.

How many fields should be included in a search result set?

While a search document might consist of a large number of fields, typically only a few are needed to represent each document in the result set. On a query request, append $select=<field list> to specify which fields include in the response. A field must be attributed as "retrievable" in the index to be included in a result.


1 Answers

The issue is that if you don't specify delimiters, search.in assumes that spaces and commas are delimiters. Since your values have spaces in them, you'll need to specify your own delimiter parameter. For example, assuming your values don't contain commas, you can do this:

$filter=search.in(ProductCategory, 'Garden,Sport and Games', ',')

Note the lack of a space after the comma after Garden.

In general you can't use characters as delimiters if those characters are present in the literal values.

The sample that you mentioned from our docs is incorrect. We'll make sure it gets fixed. Sorry for the confusion.

like image 139
Bruce Johnston Avatar answered Sep 22 '22 15:09

Bruce Johnston