在弹性搜索中使用同义词进行搜索

时间:2016-03-16 11:39:04

标签: php magento elasticsearch synonym

我用同义词实现搜索。         这些是使用同义词进行搜索的更改。         这是我在索引中的设置。我使用了泡泡搜索扩展并修改了该代码。

$indexSettings['analysis']['analyzer'] = array(
                'std' => array( 
                'tokenizer' => 'standard',
                'char_filter' => 'html_strip', // strip html tags
                'filter' => array('standard', 'elision', 'asciifolding',                             'lowercase', 'stop', 'length'),
                ),
                'keyword' => array(
                    'tokenizer' => 'keyword',
                    'filter' => array('asciifolding', 'lowercase'),
                ),
                'keyword_prefix' => array(
                    'tokenizer' => 'keyword',
                    'filter' => array('asciifolding', 'lowercase', 'edge_ngram_front'),
                ),
                'text_prefix' => array(
                    'tokenizer' => 'standard',
                    'char_filter' => 'html_strip', // strip html tags
                    'filter' => array('standard', 'elision', 'asciifolding', 'lowercase', 'stop', 'edge_ngram_front'),
                ),
                'text_suffix' => array(
                    'tokenizer' => 'standard',
                    'char_filter' => 'html_strip', // strip html tags
                    'filter' => array('standard', 'elision', 'asciifolding', 'lowercase', 'stop', 'edge_ngram_back'),
                ),
/*This is my analyzer for synonym*/
                'synonym' => array(
                    'tokenizer' => 'standard',
                    'type' => 'custom',
                    // 'char_filter' => 'html_strip', // strip html tags
                    'filter' => array('synonym','standard', 'elision', 'asciifolding', 'lowercase', 'stop',"kstem", "length" )
                ),

            );

    $indexSettings['analysis']['filter'] = array(
                'edge_ngram_front' => array(
                    'type' => 'edgeNGram',
                    'min_gram' => 2,
                    'max_gram' => 10,
                    'side' => 'front',
                ),
                'edge_ngram_back' => array(
                    'type' => 'edgeNGram',
                    'min_gram' => 2,
                    'max_gram' => 10,
                    'side' => 'back',
                ),
                'stop' => array(
                    'type' => 'stop',
                    'stopwords' => '_none_',
                ),
                'length' => array(
                    'type' => 'length',
                    'min' => 2,
                ),
/*This is filter for synonym */
                'synonym' => array(
                    'type' => 'synonym',
                    'expand' => true,
                    'synonyms_path' => 'synonyms.txt',
                ),
      );
     $properties[$key]['analyzer'] = 'synonym';

我得到的结果却没有达标。         例如lkjhgf =>芳基乙酰胺脱乙酰酶如3         如果我搜索lkjhgf然后它将给出结果         芳基乙酰胺脱乙酰酶如1         芳基乙酰胺脱乙酰酶如2         芳基乙酰胺脱乙酰酶如3         芳基乙酰胺脱乙酰酶如4

    I want exact match and my fuzzy login is also disabled.

0 个答案:

没有答案