考虑以下查询
"-a:d +b:2 +(-c:[* TO *])"
此查询未返回任何结果。
"-a:d +b:2 -c:[* TO *]"
而此查询返回结果。
对于#1,
它先评估 c,然后评估 a,然后评估 b。
对于#2
它先评估a,然后评估b,然后评估c。
理想情况下是相同的。这有什么区别?
请帮忙。提前致谢。它是标准查询解析器。
将 Solr 中查询的每个部分视为代表一组文档。文档要么是集合的一部分,要么不是集合的一部分,然后您可以在这些集合之间执行操作作为查询的一部分。
AND
表示“应包含在这两个集合中的文档”(交集),OR
表示“应包含在这两个集合中的文档”(并集),NOT
或 -
的意思是“从另一组中减去该组”。
给出您的第一个查询,它被解析为:
-a:d # subtract the set of documents matched by "a:d" from the existing set
+b:2 # AND includes the set of documents matched by `b:2` (+ => needs to be present)
+(-c:[* TO *])" # AND include the set of documents matched by:
# the empty set minus the set of documents matching `c:[* TO *]`
如果我们忽略 Solr 有时会在您的查询中添加所有匹配文档的集合的前缀,以便您以表示“所有文档”而不是“无文档”的集合开始,并假设我们始终以空集合开始,我们可以看到为什么我们没有收到文件:
current: empty_set, statement: -a:d
subtract the set matched by `a:d`
# result is still an empty set
current: empty_set, statement +b:2
add the set matched by `b:2`
# result is a set that contains documents with `b:2`
current: (b:2), statement +(-c:[* TO *])
INTERSECT it (since its given with +) with the set represented by:
empty_set
subtract the set matched by `c:[* TO *]` (documents with a value in `c`)
# result is still an empty set
# result is an empty set, since the internal part is an empty set and we require a match through `+`
如果我们将最后一步更改为首先包含所有文档 (
*:*
):
current: (b:2), statement +(*:* -c:[* TO *])
INTERSECT (since its given with +) with the set represented by:
all_documents
subtract the set matched by `c:[* TO *]` (documents with a value in `c`)
# result is all_documents except those with a value in `c`)
# resulting set: documents with `b:2` and without a value for `c`.
# ^- not "either set", but those that are in both sets - so an intersection