0
votes

I am submitting a basic query to my index and then using data from the returned results to further filter that result set using the $filter parameter and the search.in function. However, when I apply the filter, it subsequently returns 0 results when I would expect it to return a subset of the original result set. I am able to reproduce this issue using the Search Explorer tool in the Azure Search portal.

My initial query is:

search=ski

... my subsequent filter is ...

search=ski&$filter=search.in(categories,'Ski Resorts','|')

Initial query returns a bunch of results, many of which have Ski Resorts in the categories field. The second query returns no results.

In the index definition, the categories field is defined as an Edm.String field and searchable, filterable, retrievable and facetable. It contains a comma-separated list of categories for the document. My goal is to leverage these categories to allow users to further filter the result set.

Anyone know if I am using the search.in parameter incorrectly? I am going to experiment with other methods for achieving my outcome but curious what might not be right here.

2

2 Answers

1
votes

Not surprisingly it was operator error but I definitely learned a good bit.

First, my goal is to allow users to filter down to categories they want. My index field could contain multiple values and I was originally trying to implement it with:

$filter=search.in(categories,pipeDelimitedTags,'|')

where the categories field contains a comma-delimited list of category tags.

However, that expression assumes there is only a single value in the categories field.

I updated my index and added a string collection and updated my query expression to:

$filter=categoriesCollection/any(c: search.in(c,pipeDelimitedTags,'|'))

Now my filter expression appears to be working!

In summary, two key changes:

  1. Copy my comma-delimited string into a Collection(Edm.String)
  2. Use the OData Collection any operator with the search.in function

For reference, OData Collection operators in Azure Cognitive Search

Thank you for the pointers!

0
votes

I set up an index with the hotels sample data set to test this. In that data set there is an equivalent example with a searchable property, Category, that contains 'Suite'. Similarly, the word 'suite' appears in the searchable Description property.

My first example yields 20 hits, including an entry where Category is set to 'Suite'.

search=suite

Then I add the search.in. Unexpectedly, I get 0 hits.

search=suite&$filter=search.in(Category, 'suite', '|')

After some experimenting I try to switch to uppercase 'Suite', and I get 1 hit.

search=suite&$filter=search.in(Category, 'Suite', '|')

So, it appears to be a case-sensitivity issue. Surprisingly, many of the built-in analyzers are defined without lowercase. Ask me how I know...