问题
We have a azure web application where in there is one search box, when we enter text with double quotes like "App Service" it list records with "App service" however it also includes records having special characters in between the words like "App/Service". We want the search engine to return records that match the search phrase exactly (don't include records having special characters in between the search terms).
回答1:
In this scenario, you want to index the entire content of a field as a single token. Take a look at Custom Analyzers in Azure Search, and the keyword
analyzer in particular.
回答2:
In your case the standard
analyzer breaks the term App/Service into two individual terms app and service at indexing time. That's why the phrase "App Service" matches the document with App/Service - both versions look the same to the search engine.
If the term App/Service constitutes the entirety of the content of a field, you can index the content of that field as a single token using the keyword
analyzer. Learn more here: Custom Analyzers in Azure Search.
The keyword
analyzer won't be a good option if the term App/Service occurs as a part of a sentence. In that case you can replace the /
character with another character that the standard
tokenizer doesn't split on, for example: _
. Use the mappping
character token filter for that:
charFilters: [
{
"name":"map_char_mapping",
"@odata.type":"#Microsoft.Azure.Search.MappingCharFilter",
"mappings":[ "/=>_" ]
}
]
The following post will help you understand how lexical analyzers are applied at search and indexing time: How to practially use a keywordanalyzer in azure-search?
来源:https://stackoverflow.com/questions/42361449/azure-search-exact-phrase-matching