ElasticSearch - 用连字符搜索名称 [英] ElasticSearch - Searching with hyphens in name
问题描述
我的目录中有产品有't-shirt'
他们的名字。但是,如果我输入'tshirt'
,则搜索结果不会出现。
我该怎么做
我已经遵循此教程,并为索引实施以下内容:
'analysis'=> array(
'analyzer'=> array(
'indexAnalyzer'=> array(
'type'=>'custom',
'tokenizer'=> '空白',
'filter'=> array('smallcase','mySnowball')
),
'searchAnalyzer'=>数组(
'type'= "'custom',
'tokenizer'=>'空格',
'filter'=>数组('smallcase','mySnowball')
)
) ,
'filter'=>数组(
'mySnowball'=>数组(
'type'=>'snowball',
'language'=&英文'
)
)
)
您可以尝试使用映射字符过滤器删除连字符:
这样会删除连字符:
{
index:{
analysis:{
char_filter:{
my_mapping:{
type:mapping,
mappings:[ - => ;
}
},
analyzer:{
custom_with_char_filter:{
tokenizer:standard,
char_filter :[my_mapping]
}
}
}
}
}
这是一个钝的力量仪器,因为它会剥除所有连字符,但它应该使T恤和t恤匹配
I have a product catalog which I am indexing in ElasticSearch using the Elastica client. I am very new to ElasticSearch BTW.
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'
.
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:
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"]
}
}
}
}
}
it's something of a blunt force instrument as it will strip all hyphens but it should make "t-shirt" and "tshirt" match
这篇关于ElasticSearch - 用连字符搜索名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!