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

送分小仙女□ 提交于 2019-12-10 15:36:58

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/4999998/can-i-make-lucene-return-an-unlimited-number-of-search-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!