Search code examples
azure-cognitive-search

In OData search.in, if I leave the default delimiter of ', ' or ' ', no value is returned


I'm testing out the search api filtering and have a relatedTags parameter that is of type Collection(Edm.String) and when I perform the following filter:

relatedTags/any(rt: search.in(rt, 'Tag 3, Tag 2'))

which is equivalent to

relatedTags/any(rt: rt eq 'Tag 3' or rt eq 'Tag 2')

Only the latter will return results where the string array, relatedTags, has either of those values. If I set the delimiter to '|' or ',':

relatedTags/any(rt: search.in(rt, 'Tag 3|Tag 2', '|'))

will it return the same as the eq example above.

Even specifying the delimiter as ' ,' or ' ' won't return results.

relatedTags/any(rt: search.in(rt, 'Tag 3, Tag 2', ' ,'))

The search.in OData language ref page has an example that is the same as what I've written in the first example:

Rooms/any(room: room/Tags/any(tag: search.in(tag, 'wifi, tub')))

Solution

  • Your query is not the same as the example because the values in your comma-separated list have spaces inside them. You need to set the delimiter to just comma, not space or comma:

    relatedTags/any(rt: search.in(rt, 'Tag 3,Tag 2', ','))
    

    You will likely also need to trim whitespace around your tags in order for this to work.