Lucene:查询和过滤器有什么区别
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
过滤不会影响未过滤文档的分数计算。
例如,想象一下以下文档:
现在假设您执行以下查询:
在该查询中,文档 2 的分数高于文档 1 的分数(因为
loc
是在文档分数中计算的),使用过滤器:
在此查询中,文档 1 的分数高于文档 2 的分数。
请原谅 Solr 风格的格式,但总体概念很清晰。
使用过滤器的其他原因是出于缓存目的,过滤器与查询分开缓存,因此如果您有包含静态部分的动态查询,则按静态部分进行过滤是有意义的。通过这种方式,索引遍历仅限于过滤文档的子集。
Filter doesn't affect the computation of the score of the non-filtered documents.
For instance imagine the following docs:
now let's say you do the following query:
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:
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.
可以将
Query
传递给Searcher
来查找文档。Filter
不能;它只能修改查询
产生的结果。实现新的
Query
类型相当复杂,需要了解Lucene内部的关系,例如Weight
、Scorer
和Similarity
。Filter
实现可能相当简单,并且根本不与IndexReader
交互。A
Query
can be passed to aSearcher
to find documents. AFilter
cannot; it can only modify the results produced by aQuery
.Implementing a new
Query
type is fairly complicated, and requires an understanding of the relationship of Lucene internals likeWeight
,Scorer
, andSimilarity
. AFilter
implementation could be fairly simple, and not interact with theIndexReader
at all.关闭数据库后,过滤器的选择就会消失。但是当您关闭查询并再次打开它时,它仍然存在。
您还可以使用表单创建查询。但您不能在表单中使用过滤器。
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.