Search code examples
azurelucenesearch-engineazure-cognitive-search

Azure Search - Find matches within a word like "contains"


I use Azure Search which in turn uses Lucene. Is there any way to make search not that strict. What I need is when searching for "term" should match documents with terms that contain "term".

Serching fox term should match "PrefixTerm", "TermSuffix", "PrefixTermSuffix"

Serching fox part2 should match "part1part2", "part2part3", "part1part2part3"

I need to run search query which has several terms like

"term part2"

To match documents like:

{ someField:"... PrefixTermSuffix ... part1part2part3 ..." }
{ someField:"... PrefixTerm ... part2part3 ..." }
etc

Solution

  • You can use regex expression in Lucene query syntax in Azure Search. In your example, you can construct a regex query like /.term./ /.part2./ to find the documents with terms that contains the two search terms as substrings.

    https://[service name].search.windows.net/indexes/[search index]/docs?api-version=2016-09-01&queryType=full&search=/.*term.*/ /.*part2.*/

    Azure Search supports two query syntaxes, simple and full. The latter enables the Lucene query syntax. Please see our documentation (https://learn.microsoft.com/en-us/rest/api/searchservice/lucene-query-syntax-in-azure-search) to learn more about the capabilities.