您可以使用同义词过滤器转换The The
成单个令牌,例如thethe
停用词过滤器不会删除它。
首先,配置分析器:
curl -XPUT 'http://127.0.0.1:9200/test/?pretty=1' -d '
{
"settings" : {
"analysis" : {
"filter" : {
"syn" : {
"synonyms" : [
"the the => thethe"
],
"type" : "synonym"
}
},
"analyzer" : {
"syn" : {
"filter" : [
"lowercase",
"syn",
"stop"
],
"type" : "custom",
"tokenizer" : "standard"
}
}
}
}
}
'
然后用字符串测试一下"The The The Who"
.
curl -XGET 'http://127.0.0.1:9200/test/_analyze?pretty=1&text=The+The+The+Who&analyzer=syn'
{
"tokens" : [
{
"end_offset" : 7,
"position" : 1,
"start_offset" : 0,
"type" : "SYNONYM",
"token" : "thethe"
},
{
"end_offset" : 15,
"position" : 3,
"start_offset" : 12,
"type" : "<ALPHANUM>",
"token" : "who"
}
]
}
"The The"
已被标记为"the the"
, and "The Who"
as "who"
因为前面的"the"
已被停用词过滤器删除。
停下还是不停下
这让我们回到是否应该包含停用词的问题?你说:
I know I can ignore the stop words list completely
but this is not what I want since the results searching
for other bands like "the who" would explode.
你是什么意思?怎么爆?索引大小?表现?
最初引入停用词是为了通过删除可能对查询的相关性几乎没有影响的常用词来提高搜索引擎性能。然而,从那时起我们已经取得了很大的进步。我们的服务器的功能比 80 年代要强大得多。
索引停用词不会对索引大小产生巨大影响。例如,要索引单词the
意味着向索引添加单个术语。您已经有数千个术语 - 对停用词建立索引不会对大小或性能产生太大影响。
其实更大的问题是the
非常常见,因此对相关性的影响很小,因此搜索"The The concert Madrid"
会更喜欢Madrid
超过其他条款。
这可以通过使用来缓解shingle过滤器,这将导致这些标记:
['the the','the concert','concert madrid']
While the
可能很常见,the the
不是,所以排名会更高。
您不会单独查询叠瓦字段,但可以将对标准分析器标记化的字段(无停用词)的查询与对叠瓦字段的查询结合起来。
我们可以使用多字段来分析text
领域有两种不同的方式:
curl -XPUT 'http://127.0.0.1:9200/test/?pretty=1' -d '
{
"mappings" : {
"test" : {
"properties" : {
"text" : {
"fields" : {
"shingle" : {
"type" : "string",
"analyzer" : "shingle"
},
"text" : {
"type" : "string",
"analyzer" : "no_stop"
}
},
"type" : "multi_field"
}
}
}
},
"settings" : {
"analysis" : {
"analyzer" : {
"no_stop" : {
"stopwords" : "",
"type" : "standard"
},
"shingle" : {
"filter" : [
"standard",
"lowercase",
"shingle"
],
"type" : "custom",
"tokenizer" : "standard"
}
}
}
}
}
'
然后使用一个multi_match
查询来查询该字段的两个版本,为叠瓦版本提供更多“提升”/相关性。在这个例子中text.shingle^2
意味着我们想要将该字段提高 2:
curl -XGET 'http://127.0.0.1:9200/test/test/_search?pretty=1' -d '
{
"query" : {
"multi_match" : {
"fields" : [
"text",
"text.shingle^2"
],
"query" : "the the concert madrid"
}
}
}
'