gpt4 book ai didi

elasticsearch - ElasticSearch/Elastica:搜索包含 “and”或其他停用词的确切术语

转载 作者:行者123 更新时间:2023-12-03 02:09:47 25 4
gpt4 key购买 nike

我正在尝试让ES QueryString匹配其中包含“和”的搜索词,但是到目前为止我尝试过的一切(尝试使用不同的分析器,tokenziers,过滤器)均无效。用MySQL的话,我想要的是:

WHERE field LIKE '%abbot and costello%'

我已经尝试了各种配置,这是我当前正在使用的配置(由于它与“abbot”(带有尾随空格)匹配,但仍不匹配任何与“and”匹配的东西,因此略有改进:
$eI->create(array(
'analysis' => array(
'analyzer' => array(
'indexAnalyzer' => array(
'type' => 'custom',
'tokenizer' => 'SQLedgeNGram',
'filter' => array(
'lowercase',
),
),
'searchAnalyzer' => array(
'type' => 'custom',
'tokenizer' => 'SQLedgeNGram',
'filter' => array(
'lowercase',
),
)
),
'tokenizer' => array(
'SQLedgeNGram' => array(
'type' => 'edgeNGram',
'min_gram' => 2,
'max_gram' => 35,
'side' => 'front'
),
'standardNoStop' => array(
'type' => 'standard',
'stopwords' => ''
)
)
)
), true
);

这是我的测试用例字段值:
Abbott and Costello - Funniest Routines, Vol. 

尝试使用各种分析器,我似乎无法使其匹配包含“and”的任何内容。

结果:
searching [abbot] 
@ searchAnalyzer total results: 1
@ standard total results: 1
@ simple total results: 1
@ whitespace total results: 1
@ keyword total results: 1


searching [abbot ]
@ searchAnalyzer total results: 1
@ standard total results: 1
@ simple total results: 1
@ whitespace total results: 1
@ keyword total results: 1


searching [abbot and c]
searchAnalyzer total results: 0
standard total results: 0
simple total results: 0
whitespace total results: 0
keyword total results: 0


searching [abbot and cost]
searchAnalyzer total results: 0
standard total results: 0
simple total results: 0
whitespace total results: 0
keyword total results: 0


searching [abbot and costello]
searchAnalyzer total results: 0
standard total results: 0
simple total results: 0
whitespace total results: 0
keyword total results: 0


searching [abbot costello]
searchAnalyzer total results: 0
standard total results: 0
simple total results: 0
whitespace total results: 0
keyword total results: 0

最佳答案

您在查询中有错字(在abbott中缺少第二个t)。您也不需要通过ngram运行搜索。搜索标记器可以是关键字,并且对于少于35个字符的短语仍然有效。而且,顺便说一句,edgeNGram将只给您尾随通配符。对于前导和尾随通配符,您需要使用nGram过滤器。

关于elasticsearch - ElasticSearch/Elastica:搜索包含 “and”或其他停用词的确切术语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16007315/

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