Skip to content

Commit 2e2c72a

Browse files
committed
100_Full_Text_Search/10_Multi_word_queries 多次查询 翻译完毕.
1 parent 1d35340 commit 2e2c72a

File tree

1 file changed

+26
-50
lines changed

1 file changed

+26
-50
lines changed

100_Full_Text_Search/10_Multi_word_queries.md

Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
[[match-multi-word]]
2-
=== Multiword Queries
31
##多词查询
42

53
如果一次只能查询一个关键词,全文检索将会很不方便。幸运的是,用``match``查询进行多词查询也很简单:
@@ -48,19 +46,16 @@
4846
]
4947
}
5048

51-
<1> 文档4的相关度最高,因为包含两个``"brown"``和一个``"dog"``
49+
<1> 文档4的相关度最高,因为包含两个"brown"和一个"dog"。
5250

53-
<2> 文档2和3都包含一个``"brown"``和一个``"dog"``,且``'title'``字段长度相同,所以相关度相等。
51+
<2> 文档2和3都包含一个"brown"和一个"dog",且'title'字段长度相同,所以相关度相等。
5452

55-
<3> 文档1只包含一个``"brown"``,不包含``"dog"``,所以相关度最低。
53+
<3> 文档1只包含一个"brown",不包含"dog",所以相关度最低。
5654

5755
因为``match``查询需要查询两个关键词:``"brown"````"dog"``,在内部会执行两个``term``查询并综合二者的结果得到最终的结果。``match``的实现方式是将两个``term``查询放入一个``bool``查询,``bool``查询在之前的章节已经介绍过。
5856

5957
重要的一点是,``'title'``字段包含_至少一个_查询关键字的文档都被认为是符合查询条件的。匹配的单词数越多,文档的相关度越高。
6058

61-
[[match-improving-precision]]
62-
==== Improving Precision
63-
6459
### 提高精度
6560

6661
匹配包含任意个数查询关键字的文档可能会得到一些看似不相关的结果,这是一种霰弹策略(shotgun approach)。然而我们可能想得到包含_所有_查询关键字的文档。换句话说,我们想得到的是匹配``'brown AND dog'``的文档,而非``'brown OR dog'``
@@ -79,53 +74,34 @@
7974
}
8075
}
8176

82-
<1> The structure of the ``match`` query has to change slightly in order to
83-
accommodate the ``'operator'`` parameter.
84-
77+
<1> 为了加入``'operator'``参数,``match``查询的结构有一些不同。
78+
8579
这个查询会排除文档1,因为文档1只包含了一个查询关键词。
8680

87-
[[match-precision]]
88-
==== Controlling Precision
89-
9081
### 控制精度
9182

9283
_all__any_ 之间的选择有点过于非黑即白。如果用户指定了5个查询关键字,而一个文档只包含了其中的4个?将``'operator'``设置为``'and'``会排除这个文档。
9384

9485
有时这的确是用户想要的结果。但在大多数全文检索的使用场景下,用户想得到相关的文档,排除那些不太可能相关的文档。换句话说,我们需要介于二者之间的选项。
9586

96-
The `match` query supports((("match query", "minimum_should_match parameter")))((("minimum_should_match parameter"))) the `minimum_should_match` parameter, which allows
97-
you to specify the number of terms that must match for a document to be considered
98-
relevant. While you can specify an absolute number of terms, it usually makes
99-
sense to specify a percentage instead, as you have no control over the number of words the user may enter:
100-
101-
[source,js]
102-
--------------------------------------------------
103-
GET /my_index/my_type/_search
104-
{
105-
"query": {
106-
"match": {
107-
"title": {
108-
"query": "quick brown dog",
109-
"minimum_should_match": "75%"
110-
}
111-
}
112-
}
113-
}
114-
--------------------------------------------------
115-
// SENSE: 100_Full_Text_Search/05_Match_query.json
116-
117-
When specified as a percentage, `minimum_should_match` does the right thing:
118-
in the preceding example with three terms, `75%` would be rounded down to `66.6%`,
119-
or two out of the three terms. No matter what you set it to, at least one term
120-
must match for a document to be considered a match.
121-
122-
[NOTE]
123-
====
124-
The `minimum_should_match` parameter is flexible, and different rules can
125-
be applied depending on the number of terms the user enters. For the full
126-
documentation see the
127-
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html#query-dsl-minimum-should-match
128-
====
129-
130-
To fully understand how the `match` query handles multiword queries, we need
131-
to look at how to combine multiple queries with the `bool` query.
87+
``match``查询有``'minimum_should_match'``参数,参数值表示被视为_相关_的文档必须匹配的关键词个数。参数值可以设为整数,也可以设置为百分数。因为不能提前确定用户输入的查询关键词个数,使用百分数也很合理。
88+
89+
GET /my_index/my_type/_search
90+
{
91+
"query": {
92+
"match": {
93+
"title": {
94+
"query": "quick brown dog",
95+
"minimum_should_match": "75%"
96+
}
97+
}
98+
}
99+
}
100+
101+
``'minimum_should_match'``被设置为百分数时,查询进行如下:在上面的例子里,``'75%'``会被下舍为``'66.6%'``,也就是2个关键词。不论参数值为多少,进入结果集的文档至少应匹配一个关键词。
102+
103+
####[提示]
104+
105+
``'minimum_should_match'``参数很灵活,根据用户输入的关键词个数,可以采用不同的匹配规则。更详细的内容可以查看[文档](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html#query-dsl-minimum-should-match)
106+
107+
要全面理解``match``查询是怎样处理多词查询,我们需要了解怎样用``bool``查询合并多个查询。

0 commit comments

Comments
 (0)