我们使用Azure Cognitive Search作为搜索图像的搜索引擎。分析器是Lucene标准的,当用户搜索"苏格兰风景"时;我们的一些用户声称他们的图像丢失了。然后,他们必须添加关键字"风景"。在他们的图像中,以便搜索引擎可以找到他们。
将分析器更改为"en-lucene";或";en-microsoft"似乎只有更小的搜索结果,我们不喜欢我们的用户。
Azure Cognitive Search似乎不能区分单数和复数单词。为了解决这个问题,我在数据库中创建了一个字典,使用词形变化并尝试操纵搜索词:
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,它将单词减少到其词根,因此它适合于复数到单数的场景(搜索"landscape")。返回"landscapes"one_answers"landscape"
"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"
}
]
我还没有想出另一种方法。如果用户搜索"apple";它应该返回"苹果"one_answers"apples".
均为en。Lucene和en。微软应该在这方面提供帮助,你不需要手动扩展你的屈折。我很惊讶地听到你看到他们很少回忆。一般来说,我希望这些比标准分析仪的召回率更高。您是否碰巧有多个具有不同分析程序的可搜索字段?这可能会干扰。否则,如果能看到一个具体的案例(查询/文档对以及索引定义)以进一步研究,那就太好了。
作为一个快速测试,我使用了这个小索引定义:{
"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"
}
]
}