Lucene:查询和过滤器有什么区别

发布于 2024-09-18 23:54:31 字数 135 浏览 5 评论 0原文

Lucene 查询与过滤器?

他们都做了类似的事情,比如 termquery 按术语值过滤,我猜过滤器是出于类似的目的。

什么时候使用过滤器,什么时候使用查询?

今天刚开始使用 lucene,所以试图理清概念

Lucene query vs filter?

They both does similar things like termquery filters by term value, filter i guess is there for similar purpose.

When would you use filter and when query?

Just starting on lucene today so trying to clear concept

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

疾风者 2024-09-25 23:54:31

过滤不会影响未过滤文档的分数计算。

例如,想象一下以下文档:

1.
loc: "uk", "london"
text: "i live in london, "london is the best"

2.
loc: "london avenue", "london street", "london"
text: "I like the shop in london st."

现在假设您执行以下查询:

q=+loc:"london" +text:"london"

在该查询中,文档 2 的分数高于文档 1 的分数(因为 loc 是在文档分数中计算的),

使用过滤器:

q=+text:"london" f=+loc:"london"

在此查询中,文档 1 的分数高于文档 2 的分数。

请原谅 Solr 风格的格式,但总体概念很清晰。

使用过滤器的其他原因是出于缓存目的,过滤器与查询分开缓存,因此如果您有包含静态部分的动态查询,则按静态部分进行过滤是有意义的。通过这种方式,索引遍历仅限于过滤文档的子集。

Filter doesn't affect the computation of the score of the non-filtered documents.

For instance imagine the following docs:

1.
loc: "uk", "london"
text: "i live in london, "london is the best"

2.
loc: "london avenue", "london street", "london"
text: "I like the shop in london st."

now let's say you do the following query:

q=+loc:"london" +text:"london"

in this query the score of doc 2 is higher than that of doc 1 (because loc is calculated in the document score)

using a filter:

q=+text:"london" f=+loc:"london"

in this query the score of doc 1 is higher than that of doc 2.

Excuse the Solr style formatting but the overall notion is clear.

Other reasons for using filters are for caching purposes, filters are cached separately from queries so if you have a dynamic query with a static part it would make sense to filter by the static part. In this way the index traversal is limited to the subset of filtered docs.

你是暖光i 2024-09-25 23:54:31

可以将 Query 传递给 Searcher 来查找文档。 Filter 不能;它只能修改查询产生的结果。

实现新的Query类型相当复杂,需要了解Lucene内部的关系,例如WeightScorerSimilarityFilter 实现可能相当简单,并且根本不与 IndexReader 交互。

A Query can be passed to a Searcher to find documents. A Filter cannot; it can only modify the results produced by a Query.

Implementing a new Query type is fairly complicated, and requires an understanding of the relationship of Lucene internals like Weight, Scorer, and Similarity. A Filter implementation could be fairly simple, and not interact with the IndexReader at all.

心意如水 2024-09-25 23:54:31

关闭数据库后,过滤器的选择就会消失。但是当您关闭查询并再次打开它时,它仍然存在。

您还可以使用表单创建查询。但您不能在表单中使用过滤器。

After you close a database, the filter's selection disappears. But when you close a Query, and open it again, it will still be there.

You can also create a Query using a Form. But you cannot use Filter in a Form.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文