我试图让 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.
尝试各种分析器,我似乎无法让它匹配任何包含“和”的东西。
结果:
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