本文介绍了ElasticSearch - 在名称中使用连字符进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a product catalog which I am indexing in ElasticSearch using the Elastica client. I am very new to ElasticSearch BTW.

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

There are products in my catalog which have 't-shirt' in their names. But, they won't appear in search results if I type 'tshirt'.

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

What can I do so that 't-shirt' can also pop-up in results?

我遵循了教程并为索引:

I have followed this tutorial and implemented the following for indexes:

'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'
        )
    )
)

推荐答案

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

You can try removing the hyphen using a mapping char filter:

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

这样的事情会删除连字符:

something like this would remove the hyphen:

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

这是一种钝力工具,因为它会去除所有连字符,但它应该使t-shirt"和tshirt"匹配

it's something of a blunt force instrument as it will strip all hyphens but it should make "t-shirt" and "tshirt" match

这篇关于ElasticSearch - 在名称中使用连字符进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 05:06