Azure Search filter for “like” or “contains”

ttaylor2727 6 Reputation points
2021-01-22T05:10:30.603+00:00

What is the correct filter syntax for doing a like or contains?

I would like to pull all fileNames that contain "test" in the file name.

I've tried this in the search explorer, but it didn't work

$filter=search.in(fileName, 'test')  

or

$filter=search.ismatch('test')  

I also need to do this via the C# Azure Search:

            SearchOptions options = new SearchOptions()  
            {  
                Filter = string.Format("{0} ne '{1}'", FileManagerMetadataContants.IsFileDeleted, FileManagerMetadataContants.IsFileDeletedValue),  
                SearchMode = SearchMode.Any,  
                IncludeTotalCount = true,  
            };  

![59465-image.png][1]

Here are the versions I'm on:

Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
1,350 questions
Developer technologies | C#
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. ajkuma 28,036 Reputation points Microsoft Employee Moderator
    2021-01-22T21:36:14.607+00:00

    @ttaylor2727 ,

    There are different ways to achieve a “contains” query.

    1) You could use wildcard matching Lucene query syntax, as mentioned in this doc, however, this is potentially very slow for large indexes.

    2) You could use a custom analyzer such as NGram or EdgeNGram. This will index all the permutations of the field which creates a larger index but makes queries much faster. Check out this blog article for more information: Custom analyzers in Azure Search

    Note that the blog uses EdgeNGram which will give you a “prefix” query and not a “contains” query. Change it to “ngram” or “ngram_v2” instead. See the list of tokenizers available here: Add custom analyzers to string fields


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.