Synonym Maps in Azure Search, synonym phrases

落爺英雄遲暮 提交于 2020-01-05 06:31:08

问题


I'm trying to use synonym maps in Azure Search and i'm running into a problem. I want to have several words and phrases map into a single search query.

In other words, when i search for either:

product 123, product0123, product 0123

i want the search to return results for a query phrase:

product123.

After reading the tutorial it all seemed pretty straight forward.

I'm using .Net Azure.Search SDK 5.0 so i've done the following:

var synonymMap = new SynonymMap
{
     Name = "test-map",
     Format = SynonymMapFormat.Solr,
     Synonyms = "product 123, product0123, product 0123=>product123\n"
};  
_searchClient.SynonymMaps.CreateOrUpdate(synonymMap);

and i use the map on one of the search fields

index.Fields.First(x => x.Name == "Title").SynonymMaps = new[] {"test-map"};

So far so good. Now if i do a search for product0123 i get results for product123 as i would expect. But if i search for a phrase product 123 or product 0123 i get bunch of irrelevant results. It's almost as if the synonym maps do not work with multi word items.

So guess my question is, am i using synonym maps incorrectly or these maps only work with single word synonyms?


回答1:


Are the phrases, product 123 or product 0123, in double quotes? It is required for the phrases to be in double quotes ("product 123"). Double quotes are the operators for phrase search and in the case for synonyms, they ensure that the terms in the phrase are analyzed and matched against the rules in the synonym map as a phrase. Without it, query parser separates the unquoted phrase to individual terms and tries synonym matching on individual terms. The query becomes product OR 123 in that case.

This documentation explains how queries are parsed (stage 1) and analyzed (stage 2). The application of synonyms in done in the second stage.

To answer your second question in the comment, unfortunately double quotes are required to match multi word synonyms. However, as an application developer, you have the full control of what gets passed to the search service. For example, given a query product 123 from the user, you can re-write the query under the hood to improve precision and recall before it gets passed to the search service. Phrasing or proximity searches can be used to improve precision and wildcard (such as fuzzy or prefix searches) can be used to improve recall of the query. You would rewrite the query product 123 to something like "product 123"~10 product 123 and synonyms will apply to the phrased part of the query.

Nate



来源:https://stackoverflow.com/questions/51200616/synonym-maps-in-azure-search-synonym-phrases

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!