gpt4 book ai didi

elasticsearch - 在 Elasticsearch 中使用 asciifolding 和 UTF-8 字符进行搜索

转载 作者:行者123 更新时间:2023-11-29 02:54:33 24 4
gpt4 key购买 nike

我正在为网页上的所有名称编制索引,其中包含带有“José”等重音符号的字符。我希望能够用“Jose”和“José”搜索这个名字。

我应该如何为只有一个字段“名称”的简单索引设置索引映射和分析器?

我为名称字段设置了一个分析器,如下所示:

"analyzer": {
"folding": {
"tokenizer": "standard",
"filter": ["lowercase", "asciifolding"]
}
}

但它会将所有重音符折叠成 ASCII 等价物,并在索引“é”时忽略重音符。我希望索引中包含“é”字符,并且我希望能够使用“José”或“Jose”搜索“José”。

最佳答案

您需要保留带有重音符号的原始标记。为此,您需要重新定义自己的 asciifolding 标记过滤器,如下所示:

PUT /my_index
{
"settings" : {
"analysis" : {
"analyzer" : {
"folding" : {
"tokenizer" : "standard",
"filter" : ["lowercase", "my_ascii_folding"]
}
},
"filter" : {
"my_ascii_folding" : {
"type" : "asciifolding",
"preserve_original" : true
}
}
}
},
"mappings": {
"my_type": {
"properties": {
"name": {
"type": "text",
"analyzer": "folding"
}
}
}
}
}

之后, token josejosé 都将被索引和搜索

关于elasticsearch - 在 Elasticsearch 中使用 asciifolding 和 UTF-8 字符进行搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44827673/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com