user687554
user687554

Reputation: 11131

Azure Search - Field Value Ending

I am experimenting with Azure Search. In my search index, I have a field called "description". Some examples of entries in this field include:

"The trusted leader"
"The champions event was bested"
"Another day, another dollar"
"The player will succeed if he's well rested"
"Go on to the next event"

I am trying to create a regular expression that returns the results that end in "ted". For example, I'd like

"The champions event was bested"
"The player will succeed if he's well rested"

To be returned, but not:

"The trusted leader"

I tried the following regular expression. However, it did not work:

"search":"name:/.*(ted)$/"

I don't know why. I thought the dollar sign was used to signal the end of a string in a regular expression. It seems like it should work. Is it a bug in Azure Search?

Upvotes: 2

Views: 505

Answers (2)

Chad Campbell
Chad Campbell

Reputation: 937

As @Yahnoosh mentioned, you have to use a custom analyzer. For just matching terms that end with some characters, I do not believe you need the $. In fact, I believe you can just do this: /.*ted/.

I actually wrote a blog post this topic. It shows how to do Azure Search queries with StartsWith, EndsWith, and Contains.

I hope this helps.

Upvotes: 1

Yahnoosh
Yahnoosh

Reputation: 1972

thanks for reaching out.

In Azure Search content of your documents is broken down into terms that are then indexed. When you issue a search query the search engine tries to match query terms against the terms in the index.

For example, the sentences you provided would be split into individual words. This process is called lexical analysis and I described it here and here. By default, the search engine assumes your content is in a natural language. The standard lexical analyzer removes punctuation characters and splits on whitespace. Therefore the regex you've built was matched against each word independently, not the entire sentence.

You can customize the process of lexical analysis with custom analyzers. For example, you could use KeywordAnalyzer to tell the search engine to treat the entire document as one term.

Let me know if this helps

Upvotes: 1

Related Questions