0

Fields (All fields are filterable)

DocumentName : string
Document_types : ['type1','type2','type3']
Date : Date

I'm using .net library in order to make calls to Azure Search API.

Example A (ANY) - I want to get all the results where keyword is Text or Document_types is type1.

How would this work? below is the sample code which I'm using.

        var filters = new SearchParameters()
        {
            Filter = "document_types/any(t: search.in(t, 'type1'))",
            Skip = (1 - 1) * 99999999,
            Top = 99999999,
            IncludeTotalResultCount = true,
            OrderBy = new[] { "as_of_date desc" },
            HighlightFields = new[] { "Content" },
            HighlightPreTag = "<span class=\"search-highlight\">",
            HighlightPostTag = "</span>",
            QueryType = QueryType.Full,
            SearchMode = SearchMode.Any
        };
        var results = await indexClient.Documents.SearchAsync("/.*" + query + ".*/", filters);

Thanks in advance!

2 Answers2

1

Documentation for Filters in Azure Search states that "A filter scopes a search query to a subset of documents" i.e. we cannot have an Or condition between filter and search types. The solution/workaround is to convert the search text to a filter type using search.ismatch.

to get all the results where keyword is Text or Document_types is type1, change the Filter value to:

Filter = "Document_types/any(t: search.in(t, 'type1') or search.ismatch('Text')",

and call SearchAsync as

var results = await indexClient.Documents.SearchAsync("", filters);

Please note that this works only if the searchcriteria is not an empty string, as search.in doesn't accept empty string as its first parameter.

Matt.G
  • 3,586
  • 2
  • 10
  • 23
  • change `document_types` to `Document_types` – Matt.G May 09 '18 at 17:01
  • `search=""$filters=search.ismatchscoring('Text') OR Document_types/any(t: search.in(t, '38')&highlight=Content&HighlightPreTag=&HighlightPostTag=` I have tried this as well, it returns OR as text search results in highlights. – Mitesh Prajapati May 09 '18 at 17:49
  • Try `search=*&$filters=Document_types/any(t: search.in(t, 'type1') or search.ismatch('Text')` – Matt.G May 09 '18 at 17:56
  • it is returning results which is more than the actual records. – Mitesh Prajapati May 15 '18 at 11:03
  • Add `$count=true` like `search=*&$filters=Document_types/any(t: search.in(t, 'type1') or search.ismatch('Text')&$count=true` to see the result count. Could you check the results and find out what are the result records that were not expected? – Matt.G May 15 '18 at 12:35
0

it worked with the use of search.ismatch('{0}')function.