我们使用Azure认知搜索作为搜索图像的搜索引擎。分析器是Lucene标准,当用户搜索“苏格兰景观”时,我们的一些用户声称他们的图像丢失了。然后,他们将不得不添加关键字“景观”在他们的图像,以便搜索引擎可以找到他们。
将分析器改为"en-lucene“或"en-microsoft”似乎只有小得多的搜索结果,这是我们不喜欢的。
Azure认知搜索似乎不能区分单数词和复数词。为了解决这个问题,我在数据库中创建了一个字典,使用了拐点,并尝试操作搜索词:
foreach (var term in terms)
{
if (ps.IsSingular(term))
{
// check with db
var singular = noun.GetSingularWord(term);
if (!string.IsNullOrEmpty(singular))
{
var plural = ps.Pluralize(term);
keywords = keywords + " " + plural;
}
}
else
{
// check with db
var plural = noun.GetPluralWord(term);
if (!string.IsNullOrEmpty(plural))
{
var singular = ps.Singularize(term);
keywords = keywords + " " + singular;
}
}
}我的解决方案不是100%理想,但如果Azure认知搜索能够区分单数和复数词,那就更好了。
更新:自定义分析器可能是我问题的答案,我只需要找到正确的令牌过滤器。
更新:下面是我的自定义分析器。它移除html结构、撇号、停止词并将它们转换为小写。标记器是MicrosoftLanguageStemmingTokenizer,它将单词缩减为根词,因此适合于从复数到单数场景(搜索“景观”返回“景观”和“景观”)
"analyzers": [
{
"name": "p4m_custom_analyzer",
"@odata.type": "#Microsoft.Azure.Search.CustomAnalyzer",
"charFilters": [
"html_strip",
"remove_apostrophe"
],
"tokenizer": "custom_tokenizer",
"tokenFilters": [
"lowercase",
"remove_stopwords"
]
}
],
"charFilters": [
{
"name": "remove_apostrophe",
"@odata.type":"#Microsoft.Azure.Search.MappingCharFilter",
"mappings": ["'=>"]
}
],
"tokenizers": [
{
"name": "custom_tokenizer",
"@odata.type":"#Microsoft.Azure.Search.MicrosoftLanguageStemmingTokenizer",
"isSearchTokenizer": "false"
}
],
"tokenFilters": [
{
"name": "remove_stopwords",
"@odata.type": "#Microsoft.Azure.Search.StopwordsTokenFilter"
}
]我还没有想出另一种办法。如果用户搜索“苹果”,它应该返回“苹果”和“苹果”。
发布于 2021-03-18 21:41:08
en.lucene和en.microsoft都应该在这方面有所帮助,您不应该需要手动扩展您的侧的拐点。我很惊讶你看到他们回忆得更少。一般来说,我期望那些比标准分析器更高的召回率。你有没有可能有多个可搜索的字段和不同的分析器?这可能会干扰。否则,最好能看到一个具体的案例(查询/文档对以及索引定义)来进一步调查。
作为一个快速测试,我使用了这个小的索引定义:
{
"name": "inflections",
"fields": [
{
"name": "id",
"type": "Edm.String",
"searchable": false,
"filterable": true,
"retrievable": true,
"sortable": false,
"facetable": false,
"key": true
},
{
"name": "en_ms",
"type": "Edm.String",
"searchable": true,
"filterable": false,
"retrievable": true,
"sortable": false,
"facetable": false,
"key": false,
"analyzer": "en.microsoft"
}
]
}这些医生:
{
"id": "1",
"en_ms": "example with scottish landscape as part of the sentence"
},
{
"id": "2",
"en_ms": "this doc has one apple word"
},
{
"id": "3",
"en_ms": "this doc has two apples in it"
}对于这个搜索search=landscapes,我看到以下结果:
{
"value": [
{
"@search.score": 0.9631388,
"id": "1",
"en_ms": "example with scottish landscape as part of the sentence"
}
]
}对于search=apple,我看到:
{
"value": [
{
"@search.score": 0.51188517,
"id": "3",
"en_ms": "this doc has two apples in it"
},
{
"@search.score": 0.46152657,
"id": "2",
"en_ms": "this doc has one apple word"
}
]
}https://stackoverflow.com/questions/66531968
复制相似问题