我可以让Lucene返回无限数量的搜索结果吗? [英] Can I make Lucene return an unlimited number of search results?
问题描述
我在Java 5环境中使用Lucene 3.0.1. 我一直在研究这个问题,但是文档没有给出任何直接的答案.
使用搜索方法
TopFieldDocs search(Weight weight, Filter filter, int nDocs, Sort sort)
我总是需要提供最大数量的搜索结果 nDocs .
如果我想获得所有匹配的结果怎么办?感觉将 nDocs 设置为Integer.MAX_VALUE
是一种很简单的方法(会导致速度和内存性能下降吗?).
还有其他任何想法吗?
您正在使用没有限制的其他(更底层的)方法,并且在文档中说应用程序应仅在需要所有匹配文档的情况下才使用此选项.高级搜索API(search(Query,int))通常会更高效,因为它会跳过非高分匹配.
因此,如果您确实需要所有文档,则可以使用低级API.我怀疑,将真正高的限制传递给高级API会对性能产生重大影响.如果您需要所有文档(确实有很多文档),那么这两种方法都会很慢,尤其是在涉及排序的情况下.
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?
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.
这篇关于我可以让Lucene返回无限数量的搜索结果吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!