Can I get Lucene to return an unlimited number of search results?

I am using Lucene 3.0.1 in the Java 5 environment. I am a little versed in this problem, but the documentation did not give direct answers.

Using the search method

TopFieldDocs search(Weight weight, Filter filter, int nDocs, Sort sort) 

I always need to provide the maximum number of nDocs search results .

What if I want to get all the relevant results? It seems that installing nDocs on Integer.MAX_VALUE is a kind of hacker way to do this (and lead to reduced performance and memory speed?).

Anyone who have any ideas?

+4
source share
1 answer

You use a search method that returns the first n queries for the query.

There are other (lower-level) methods that do not have restrictions, and the documentation says that "applications should use this method if they need all the relevant documents. High-level search APIs (search (Query, int)) are usually more efficient, as he misses invisible hits. "

So, if you really need all the documents, you can use the low-level API. I doubt it matters a lot in performance for conveying a really high limit API high level. If you need all the documents (and there are really a lot of them), they will be slow anyway, especially when sorting.

+6
source

Source: https://habr.com/ru/post/1339774/


All Articles