gpt4 book ai didi

elasticsearch - 分析器自动完成名称

转载 作者:行者123 更新时间:2023-12-02 22:47:17 24 4
gpt4 key购买 nike

我希望能够自动完成姓名。

例如,如果我们有名称John Smith,我希望能够搜索JoSmJohn Sm来取回文档。

另外,我不希望jo sm与文档匹配。

我目前有这个分析仪:

return array(
'settings' => array(
'index' => array(
'analysis' => array(
'analyzer' => array(
'autocomplete' => array(
'tokenizer' => 'autocompleteEngram',
'filter' => array('lowercase', 'whitespace')
)
),

'tokenizer' => array(
'autocompleteEngram' => array(
'type' => 'edgeNGram',
'min_gram' => 1,
'max_gram' => 50
)
)
)
)
)
);

问题在于,首先我们将文本分割开,然后使用edgengrams进行标记化。

结果是: j jo joh john s sm smi smit smith
这意味着,如果我搜索 john smithjohn sm,则不会返回任何内容。

因此,我需要生成看起来像这样的 token : j jo joh john s sm smi smit smith john s john sm john smi john smit john smith

如何设置分析仪,以便生成这些额外的 token ?

最佳答案

我最终没有使用edgengrams。

我创建了一个带有standard标记器,standardlowercase过滤器的分析器。这实际上与standard分析器相同,但没有任何停用词过滤器(毕竟我们正在搜索名称,并且可能有人称为TheAn等)。

然后,将上述分析器设置为index_analyzer,并将simple设置为search_analyzer。将此设置与match_phrase_prefix查询配合使用非常有效。

这是我使用的自定义分析器(称为自动完成功能,用PHP表示):

'autocomplete' => array(
'tokenizer' => 'standard',
'filter' => array('standard', 'lowercase')
),

关于elasticsearch - 分析器自动完成名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17017216/

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