在 Lucene IndexSearcher 中查询所有结果
我正在 Lucene 的 contrib/demo 目录中使用 SearchFiles 类。我不想以分页形式搜索结果,而是想检索与查询匹配的所有文档。有没有办法用现有的 API (3.4) 来做到这一点?似乎所有搜索函数都需要一个整数来指示要返回的点击量。
演示代码如下所示
TopDocs results = searcher.search(query, 5 * hitsPerPage);
ScoreDoc[] its = results.scoreDocs;
只会返回固定数量的结果
I'm working with the SearchFiles class in Lucene's contrib/demo directory. Rather than search for results in paginated form, I want to be retrieve all documents that match the query. Is there a way to do this with the existing API (3.4)? It seems like all the search functions require an integer indicating the amount of hits to return.
The demo code looks like
TopDocs results = searcher.search(query, 5 * hitsPerPage);
ScoreDoc[] its = results.scoreDocs;
Which will only return a fixed number of results
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果使用 Lucene Reader,即 IndexReader,您可以通过编写来帮助自己。
这将确保搜索中不会遗漏任何结果。
If using a Lucene Reader, i.e. the IndexReader, you can help yourself by writing
This will ensure no result is omitted from the search.
编写您自己的
Collector
并将其用作searcher.Search(query, new MyCollector());
http://lucene.apache.org/java/3_4_0/api/core/org/apache/lucene/search/Collector.html
Write your own
Collector
and use it assearcher.Search(query, new MyCollector());
http://lucene.apache.org/java/3_4_0/api/core/org/apache/lucene/search/Collector.html