Skip to content

Commit 6dd6fc5

Browse files
committed
Merge pull request #44 from richardwei2008/p2_chapter13/10_Multi_word_queries
chapter13_part3: /100_Full_Text_Search/10_Multi_word_queries.asciidoc
2 parents 89f8e5b + ca9acfd commit 6dd6fc5

File tree

1 file changed

+20
-48
lines changed

1 file changed

+20
-48
lines changed

100_Full_Text_Search/10_Multi_word_queries.asciidoc

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
[[match-multi-word]]
2-
=== Multiword Queries
2+
=== 多词查询
33

4-
If we could search for only one word at a time, full-text search would be
5-
pretty inflexible. Fortunately, the `match` query((("full text search", "multi-word queries")))((("match query", "multi-word query"))) makes multiword queries
6-
just as simple:
4+
如果我们一次只能搜索一个词,那么全文搜索就会不太灵活,幸运的是 `match` 查询让多词查询变得简单:((("full text search", "multi-word queries")))((("match query", "multi-word query")))
75

86
[source,js]
97
--------------------------------------------------
@@ -18,7 +16,7 @@ GET /my_index/my_type/_search
1816
--------------------------------------------------
1917
// SENSE: 100_Full_Text_Search/05_Match_query.json
2018

21-
The preceding query returns all four documents in the results list:
19+
上面这个查询返回所有四个文档:
2220

2321
[source,js]
2422
--------------------------------------------------
@@ -56,33 +54,22 @@ The preceding query returns all four documents in the results list:
5654
}
5755
--------------------------------------------------
5856

59-
<1> Document 4 is the most relevant because it contains `"brown"` twice and `"dog"`
60-
once.
57+
<1> 文档 4 最相关,因为它包含词 `"brown"` 两次以及 `"dog"` 一次。
6158

62-
<2> Documents 2 and 3 both contain `brown` and `dog` once each, and the `title`
63-
field is the same length in both docs, so they have the same score.
59+
<2> 文档 2、3 同时包含 `brown` 和 `dog` 各一次,而且它们 `title` 字段的长度相同,所以具有相同的评分。
6460

65-
<3> Document 1 matches even though it contains only `brown`, not `dog`.
61+
<3> 文档 1 也能匹配,尽管它只有 `brown` 没有 `dog`
6662

67-
Because the `match` query has to look for two terms&#x2014;`["brown","dog"]`&#x2014;internally it has to execute two `term` queries and combine their individual
68-
results into the overall result. To do this, it wraps the two `term` queries
69-
in a `bool` query, which we examine in detail in <<bool-query>>.
63+
因为 `match` 查询必须查找两个词( `["brown","dog"]` ),它在内部实际上先执行两次 `term` 查询,然后将两次查询的结果合并作为最终结果输出。为了做到这点,它将两个 `term` 查询包入一个 `bool` 查询中,详细信息见 <<bool-query, 布尔查询>>。
7064

71-
The important thing to take away from this is that any document whose
72-
`title` field contains _at least one of the specified terms_ will match the
73-
query. The more terms that match, the more relevant the document.
65+
以上示例告诉我们一个重要信息:即任何文档只要 `title` 字段里包含 _指定词项中的至少一个词_ 就能匹配,被匹配的词项越多,文档就越相关。
7466

7567
[[match-improving-precision]]
76-
==== Improving Precision
68+
==== 提高精度
7769

78-
Matching any document that contains _any_ of the query terms may result in a
79-
long tail of seemingly irrelevant results. ((("full text search", "multi-word queries", "improving precision")))((("precision", "improving for full text search multi-word queries"))) It's a shotgun approach to search.
80-
Perhaps we want to show only documents that contain _all_ of the query terms.
81-
In other words, instead of `brown OR dog`, we want to return only documents
82-
that match `brown AND dog`.
70+
用 _任意_ 查询词项匹配文档可能会导致结果中出现不相关的长尾。((("full text search", "multi-word queries", "improving precision")))((("precision", "improving for full text search multi-word queries")))这是种散弹式搜索。可能我们只想搜索包含 _所有_ 词项的文档,也就是说,不去匹配 `brown OR dog` ,而通过匹配 `brown AND dog` 找到所有文档。
8371

84-
The `match` query accepts an `operator` parameter((("match query", "operator parameter")))((("or operator", "in match queries")))((("and operator", "in match queries"))) that defaults to `or`.
85-
You can change it to `and` to require that all specified terms must match:
72+
`match` 查询还可以接受 `operator` 操作符作为输入参数,默认情况下该操作符是 `or` 。我们可以将它修改成 `and` 让所有指定词项都必须匹配:
8673

8774
[source,js]
8875
--------------------------------------------------
@@ -100,27 +87,18 @@ GET /my_index/my_type/_search
10087
--------------------------------------------------
10188
// SENSE: 100_Full_Text_Search/05_Match_query.json
10289

103-
<1> The structure of the `match` query has to change slightly in order to
104-
accommodate the `operator` parameter.
90+
<1> `match` 查询的结构需要做稍许调整才能使用 `operator` 操作符参数。
10591

106-
This query would exclude document 1, which contains only one of the two terms.
92+
这个查询可以把文档 1 排除在外,因为它只包含两个词项中的一个。
10793

10894
[[match-precision]]
109-
==== Controlling Precision
95+
==== 控制精度
11096

111-
The choice between _all_ and _any_ is a bit((("full text search", "multi-word queries", "controlling precision"))) too black-or-white. What if the
112-
user specified five query terms, and a document contains only four of them?
113-
Setting `operator` to `and` would exclude this document.
97+
在 _所有_ 与 _任意_ 间二选一有点过于非黑即白。((("full text search", "multi-word queries", "controlling precision")))如果用户给定 5 个查询词项,想查找只包含其中 4 个的文档,该如何处理?将 `operator` 操作符参数设置成 `and` 只会将此文档排除。
11498

115-
Sometimes that is exactly what you want, but for most full-text search use
116-
cases, you want to include documents that may be relevant but exclude those
117-
that are unlikely to be relevant. In other words, we need something
118-
in-between.
99+
有时候这正是我们期望的,但在全文搜索的大多数应用场景下,我们既想包含那些可能相关的文档,同时又排除那些不太相关的。换句话说,我们想要处于中间某种结果。
119100

120-
The `match` query supports((("match query", "minimum_should_match parameter")))((("minimum_should_match parameter"))) the `minimum_should_match` parameter, which allows
121-
you to specify the number of terms that must match for a document to be considered
122-
relevant. While you can specify an absolute number of terms, it usually makes
123-
sense to specify a percentage instead, as you have no control over the number of words the user may enter:
101+
`match` 查询支持 `minimum_should_match` 最小匹配参数,((("match query", "minimum_should_match parameter")))((("minimum_should_match parameter")))这让我们可以指定必须匹配的词项数用来表示一个文档是否相关。我们可以将其设置为某个具体数字,更常用的做法是将其设置为一个百分数,因为我们无法控制用户搜索时输入的单词数量:
124102

125103
[source,js]
126104
--------------------------------------------------
@@ -138,18 +116,12 @@ GET /my_index/my_type/_search
138116
--------------------------------------------------
139117
// SENSE: 100_Full_Text_Search/05_Match_query.json
140118

141-
When specified as a percentage, `minimum_should_match` does the right thing:
142-
in the preceding example with three terms, `75%` would be rounded down to `66.6%`,
143-
or two out of the three terms. No matter what you set it to, at least one term
144-
must match for a document to be considered a match.
119+
当给定百分比的时候, `minimum_should_match` 会做合适的事情:在之前三词项的示例中, `75%` 会自动被截断成 `66.6%` ,即三个里面两个词。无论这个值设置成什么,至少包含一个词项的文档才会被认为是匹配的。
145120

146121
[NOTE]
147122
====
148-
The `minimum_should_match` parameter is flexible, and different rules can
149-
be applied depending on the number of terms the user enters. For the full
150-
documentation see the
123+
参数 `minimum_should_match` 的设置非常灵活,可以根据用户输入词项的数目应用不同的规则。完整的信息参考文档
151124
{ref}/query-dsl-minimum-should-match.html#query-dsl-minimum-should-match
152125
====
153126

154-
To fully understand how the `match` query handles multiword queries, we need
155-
to look at how to combine multiple queries with the `bool` query.
127+
为了完全理解 `match` 是如何处理多词查询的,我们就需要查看如何使用 `bool` 查询将多个查询条件组合在一起。

0 commit comments

Comments
 (0)