5

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.

SEG.Veenstra
  • 718
  • 1
  • 7
  • 18

1 Answers1

8

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.

Bruce Johnston
  • 8,344
  • 3
  • 32
  • 42
  • I can no longer confirm this because we are no longer using the name but a key because we needed translations. But the syntax works so I figure this is the correct answer. Thx – SEG.Veenstra Jan 11 '18 at 09:41