0

我试图让 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
4

1 回答 1

1

您在查询中有拼写错误(雅培中缺少第二个 t)。您也不需要通过 ngram 运行搜索。搜索标记器可以是关键字,它仍然适用于短于 35 个字符的短语。顺便说一下,edgeNGram 只会给你尾随通配符。对于前导和尾随通配符,您需要使用 nGram 过滤器。

于 2013-04-16T18:01:20.137 回答