6

我有一个产品目录,我使用 Elastica 客户端在 ElasticSearch 中编制索引。顺便说一句,我对 ElasticSearch 很陌生。

我的目录中有产品't-shirt'名称。但是,如果我输入它们,它们将不会出现在搜索结果中'tshirt'

我该怎么做't-shirt'才能在结果中弹出?

我已遵循教程并为索引实现了以下内容:

'analysis' => array(
    'analyzer' => array(
        'indexAnalyzer' => array(
            'type' => 'custom',
            'tokenizer' => 'whitespace',
            'filter' => array('lowercase', 'mySnowball')
        ),
        'searchAnalyzer' => array(
            'type' => 'custom',
            'tokenizer' => 'whitespace',
            'filter' => array('lowercase', 'mySnowball')
        )
    ),
    'filter' => array(
        'mySnowball' => array(
            'type' => 'snowball',
            'language' => 'English'
        )
    )
)
4

1 回答 1

6

您可以尝试使用映射字符过滤器删除连字符:

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/analysis-mapping-charfilter.html

像这样会删除连字符:

{
    "index" : {
        "analysis" : {
            "char_filter" : {
                "my_mapping" : {
                    "type" : "mapping",
                    "mappings" : ["-=>"]
                }
            },
            "analyzer" : {
                "custom_with_char_filter" : {
                    "tokenizer" : "standard",
                    "char_filter" : ["my_mapping"]
                }
            }
        }
    }
}

它是一种钝器,因为它会去掉所有连字符,但它应该使“t-shirt”和“tshirt”匹配

于 2014-05-13T20:19:28.757 回答