开发者

Can I make Lucene return an unlimited number of search results?

开发者 https://www.devze.com 2023-02-10 06:53 出处:网络
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.

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 memor开发者_StackOverflow中文版y 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号