如何在 Azure 搜索的特定字段中搜索部分字符串?

How to search for a partial string in a specific field in Azure Search?

我有一个包含 title 字段的索引。其中,我有以下文字:贝克斯菲尔德纪念医院

我希望能够通过部分字符串进行搜索。以下查询有效:

search=*&$filter=search.ismatch('bakersfield','title')
search=*&$filter=search.ismatch('memorial','title')

但是,如果我要搜索单词的部分字符串,则不会。例如:

search=*&$filter=search.ismatch('baker','title')

那么如何搜索部分单词?

回答我自己的问题以防有人需要这个。

您可以像这样使用 * 运算符:

search=*&$filter=search.ismatch('baker*','title')

但是,这仅适用于 starts with 搜索。它不适用于包含或结尾。例如,以下内容不起作用:

search=*&$filter=search.ismatch('*field','title')

在您的示例中,您使用了 search.ismatch() 而未指定查询类型。这意味着它将默认为 simple 模式,仅支持后缀通配符。

匹配“centre”和“center”的示例:

search=*&$filter=search.ismatch('medical cent*','title','full','all')

如上面通配符 link 中所述,您不能使用 * 开始通配符查询,但您可以在 full 模式下使用正则表达式语法。这应该很好地转化为您的用例。

匹配“senter”和“center”的示例:

search=*&$filter=search.ismatch('/.*enter/','title','full','all')