【问题标题】:Wildcard search startwith in Azure search not working properlyAzure 搜索中的通配符搜索 startwith 无法正常工作
【发布时间】:2020-05-08 13:39:40
【问题描述】:

luncene查询语法中的通配符搜索,带*的后缀是单词。我需要像eg1一样开头:搜索:“关联*”应该给我

[{
    "field1": "Associated for"
}, {
    "field1": "Associates for"
}, {
    "field1": "Associates word"
}]

但它会返回

[{
    "field1": "you Associated for"
}, {
    "field1": "Associates for"
}, {
    "field1": "word Associates with"
}]

谁能帮我找到解决办法。

eg2 : "search":"word associate*"

预期结果

[{
    "field1": "word Associated"
}, {
    "field1": "word Associated are"
}, {
    "field1": "word Associates with"
}]

如果我使用关键字分析器,它会为我提供 eg1 预期的结果,但对于 eg: ("search":"associates for*") search 给了我

[{
    "field1": "forest are located"
}, {
    "field1": "fort are build with"
}, {
    "field1": "fore are"
}]

预期结果

[{
    "field1": "Associates for"
}, {
    "field1": "Associates for abc"
}, {
    "field1": "Associates for xyz"
}]

【问题讨论】:

    标签: search full-text-search wildcard azure-cognitive-search azure-search-.net-sdk


    【解决方案1】:

    结果(虽然不是您需要的)是正确的。您正在搜索“field1”包含关联*的文档*

    所以

    "field1":"you Associated for""field1":"word Associates with" 是正确的。

    你可以在这里找到一个很好的解释https://stackoverflow.com/a/57703999/1384539

    要生成您想要的内容,您需要使用关键字分析器,以便将整个 field1 值标记为单个标记。

    https://docs.microsoft.com/en-us/azure/search/index-add-custom-analyzers

    作为另一种选择,您可以尝试使用正则表达式,但恐怕它可能会很昂贵,具体取决于您索引中的文档数量。

    https://docs.microsoft.com/en-us/azure/search/query-lucene-syntax?redirectedfrom=MSDN#bkmk_regex

    【讨论】:

    • 感谢 Thiago Custodio 的帮助。如果我将关键字分析器用于例如:“搜索”:“关联*”进行此搜索,它会给我预期的结果。但是对于“搜索”:“单词关联*”给了我错误的结果(请您检查我编辑的问题)。我需要像输入字母一样进行搜索
    • 这是默认分析器的工作方式。换句话说,您要求的是“for*”或“associates”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-04
    • 2021-11-10
    • 2017-01-28
    • 2013-12-23
    • 2015-07-27
    • 2014-07-17
    相关资源
    最近更新 更多