我可以让 Lucene 返回无限数量的搜索结果吗?
我在 Java 5 环境中使用 Lucene 3.0.1。 我一直在研究这个问题,但文档没有给出任何直接答案。
使用搜索方法
TopFieldDocs search(Weight weight, Filter filter, int nDocs, Sort sort)
我总是需要提供最大数量的搜索结果nDocs。
如果我想获得所有匹配结果怎么办?感觉将 nDocs 设置为 Integer.MAX_VALUE
是一种很奇怪的方法(并且会导致速度和内存性能下降?)。
还有谁有任何想法吗?
I am using Lucene 3.0.1 in a Java 5 environment.
I've been researching this issue a little bit, but the documentation hasn't given any direct answers.
Using the search method
TopFieldDocs search(Weight weight, Filter filter, int nDocs, Sort sort)
I always need to provide a maximum number of search results nDocs.
What if I wanted to have all matching results? It feels like setting nDocs to Integer.MAX_VALUE
is a kind of hacky way to do this (and would result in speed and memory performance drop?).
Anyone else who has any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在使用 返回前 n 个的搜索方法 em> 查询命中。
有 其他(更低级)方法没有限制,并且在文档中说“应用程序应该只使用这个如果他们需要所有匹配的文档,则高级搜索 API (search(Query, int)) 通常更有效,因为它会跳过非高分命中。”
因此,如果您确实需要所有文档,则可以使用低级 API。我怀疑将真正的高限制传递给高级 API 是否会对性能产生很大影响。如果您需要所有文档(而且确实有很多文档),那么无论哪种方式都会很慢,特别是在涉及排序的情况下。
You are using a search method that returns the top n hits for a query.
There are other (more low-level) methods that do not have the limitation, and it says in the documentation that "applications should only use this if they need all of the matching documents. The high-level search API (search(Query, int)) is usually more efficient, as it skips non-high-scoring hits.".
So if you really need all documents, you can use the low-level API. I doubt that it makes a big difference in performance to passing a really high limit to the high-level API. If you need all documents (and there really are a lot of them), it is going to be slow either way, especially if sorting is involved.