1
votes

I have an index for which I need to combine search string with filter string using OR logic - so, it will return all matches for search string combined with all matches for filter

For example, I have a room complex type property with optional description and optional walls' colour as integer.

How could I write a query that would use OR logic between query and filter?

So, when 1 and 2 represent black and dark blue, it would be something like

{
    "search": "room/description: (\"dark walls\")",
    "queryType": "full",
    "filter": "room/wallColour eq 1 or room/wallColour eq 2 or room/wallColour eq null",
    "top": 10
}

but there is OR between search and filter.

or, for the .NET sdk call (with OR logic between filter and query):

var options = new SearchOptions()
{ 
  Size = pageSize,
  QueryType = SearchQueryType.Full,
  Filter = filter
};
await searchClient.SearchAsync<Room>(query, options);

If it is possible to move int-specific and null-specific part from filter to search, I would not mind doing it either, just don't know how.

I don't want to convert int fields into string to be able to search as I am not in control of the index structure.

I use .net core SDK for search, but initially debug queries by calling POST to search.windows.net/indexes, so, showing how to do it either way would help me.

1

1 Answers

1
votes

You can use search.ismatch and search.ismatchscoring to introduce searches within filter expressions. More details here: https://docs.microsoft.com/en-us/azure/search/search-query-odata-full-text-search-functions

Following your example, you would write the combined filter/search as:

search.ismatchscoring('room/description: ("dark walls")', null, 'full', 'any') or room/wallColour eq 1 or room/wallColour eq 2 or room/wallColour eq null