Skip to content

Commit c40a6be

Browse files
chapter13_part4: /100_Full_Text_Search/chapter13_part1: /100_Full_Text_Search/15_Combining_queries.asciidoc
第二部分:第13章,全文搜索,组合查询
1 parent 3e31f3e commit c40a6be

File tree

1 file changed

+16
-37
lines changed

1 file changed

+16
-37
lines changed

100_Full_Text_Search/15_Combining_queries.asciidoc

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
[[bool-query]]
2-
=== Combining Queries
2+
=== 组合查询
33

4-
In <<combining-filters>> we discussed how to((("full text search", "combining queries"))), use the `bool` filter to combine
5-
multiple filter clauses with `and`, `or`, and `not` logic. In query land, the
6-
`bool` query does a similar job but with one important difference.
4+
在 <<combining-filters,组合过滤器>> 中,我们讨论过如何使用 `bool` 过滤器通过 `and` 、 `or` 和 `not` 逻辑组合将多个过滤器进行组合。在查询中, `bool` 查询有类似的功能,只有一个重要的区别。
75

8-
Filters make a binary decision: should this document be included in the
9-
results list or not? Queries, however, are more subtle. They decide not only
10-
whether to include a document, but also how _relevant_ that document is.
6+
过滤器做二元判断:文档是否应该出现在结果中?但查询更精妙,它除了决定一个文档是否应该被包括在结果中,还会计算文档的 _相关程度_ 。
117

12-
Like the filter equivalent, the `bool` query accepts((("bool query"))) multiple query clauses
13-
under the `must`, `must_not`, and `should` parameters. For instance:
8+
与过滤器一样, `bool` 查询也可以接受 `must` 、 `must_not` 和 `should` 参数下的多个查询语句。((("bool query")))比如:
149

1510
[source,js]
1611
--------------------------------------------------
@@ -30,13 +25,9 @@ GET /my_index/my_type/_search
3025
--------------------------------------------------
3126
// SENSE: 100_Full_Text_Search/15_Bool_query.json
3227

33-
The results from the preceding query include any document whose `title` field
34-
contains the term `quick`, except for those that also contain `lazy`. So
35-
far, this is pretty similar to how the `bool` filter works.
28+
以上的查询结果返回 `title` 字段包含词项 `quick` 但不包含 `lazy` 的任意文档。目前为止,这与 `bool` 过滤器的工作方式非常相似。
3629

37-
The difference comes in with the two `should` clauses, which say that: a document
38-
is _not required_ to contain ((("should clause", "in bool queries")))either `brown` or `dog`, but if it does, then
39-
it should be considered _more relevant_:
30+
区别就在于两个 `should` 语句,也就是说:一个文档不必包含((("should clause", "in bool queries"))) `brown` 或 `dog` 这两个词项,但如果一旦包含,我们就认为它们 _更相关_ :
4031

4132
[source,js]
4233
--------------------------------------------------
@@ -60,28 +51,19 @@ it should be considered _more relevant_:
6051
}
6152
--------------------------------------------------
6253

63-
<1> Document 3 scores higher because it contains both `brown` and `dog`.
54+
<1> 文档 3 会比文档 1 有更高评分是因为它同时包含 `brown` `dog`
6455

65-
==== Score Calculation
56+
==== 评分计算
6657

67-
The `bool` query calculates((("relevance scores", "calculation in bool queries")))((("bool query", "score calculation"))) the relevance `_score` for each document by adding
68-
together the `_score` from all of the matching `must` and `should` clauses,
69-
and then dividing by the total number of `must` and `should` clauses.
58+
`bool` 查询会为每个文档计算相关度评分 `_score` ,((("relevance scores", "calculation in bool queries")))((("bool query", "score calculation")))再将所有匹配的 `must` 和 `should` 语句的分数 `_score` 求和,最后除以 `must` 和 `should` 语句的总数。
7059

71-
The `must_not` clauses do not affect ((("must_not clause", "in bool queries")))the score; their only purpose is to
72-
exclude documents that might otherwise have been included.
60+
`must_not` 语句不会影响评分;((("must_not clause", "in bool queries")))它的作用只是将不相关的文档排除。
7361

74-
==== Controlling Precision
62+
==== 控制精度
7563

76-
All the `must` clauses must match, and all the `must_not` clauses must not
77-
match, but how many `should` clauses((("bool query", "controlling precision")))((("full text search", "combining queries", "controlling precision")))((("precision", "controlling for bool query"))) should match? By default, none of the `should` clauses are required to match, with one
78-
exception: if there are no `must` clauses, then at least one `should` clause
79-
must match.
64+
所有 `must` 语句必须匹配,所有 `must_not` 语句都必须不匹配,但有多少 `should` 语句应该匹配呢?((("bool query", "controlling precision")))((("full text search", "combining queries", "controlling precision")))((("precision", "controlling for bool query")))默认情况下,没有 `should` 语句是必须匹配的,只有一个例外:那就是当没有 `must` 语句的时候,至少有一个 `should` 语句必须匹配。
8065

81-
Just as we can control the <<match-precision,precision of the `match` query>>,
82-
we can control how many `should` clauses need to match by using the
83-
`minimum_should_match` parameter,((("minimum_should_match parameter", "in bool queries"))) either as an absolute number or as a
84-
percentage:
66+
就像我们能控制 <<match-precision, `match` 查询的精度>> 一样,我们可以通过 `minimum_should_match` 参数控制需要匹配的 `should` 语句的数量,((("minimum_should_match parameter", "in bool queries")))它既可以是一个绝对的数字,又可以是个百分比:
8567

8668
[source,js]
8769
--------------------------------------------------
@@ -101,10 +83,7 @@ GET /my_index/my_type/_search
10183
--------------------------------------------------
10284
// SENSE: 100_Full_Text_Search/15_Bool_query.json
10385

104-
<1> This could also be expressed as a percentage.
105-
106-
The results would include only documents whose `title` field contains `"brown"
107-
AND "fox"`, `"brown" AND "dog"`, or `"fox" AND "dog"`. If a document contains
108-
all three, it would be considered more relevant than those that contain
109-
just two of the three.
86+
<1> 这也可以用百分比表示。
11087

88+
这个查询结果会将所有满足以下条件的文档返回: `title` 字段包含 `"brown"
89+
AND "fox"` 、 `"brown" AND "dog"` 或 `"fox" AND "dog"` 。如果有文档包含所有三个条件,它会比只包含两个的文档更相关。

0 commit comments

Comments
 (0)