Lucene .NET result subsets

 ̄綄美尐妖づ 提交于 2019-12-12 17:14:23

问题


I am using Lucene .NET Let's say I want to only return 50 results starting at result 100, how might I go about that? I've searched the docs but am not finding anything. Is there something I'm missing?


回答1:


I assume you are doing this for the purpose of paging. The way this is normally done in a Lucene implementation (including Solr) is by simply executing the query normally, but only actually loading the stored data for the results you are interested in.

In a typical paging scenario, this may mean executing the same query multiple times, which may seem like a waste of resources, but with help from the system cache and possibly Lucene's caching it's not so bad. The benefit is statelessness, which allows you to scale.




回答2:


Your code should look something like this:

TopDocs topDocs = indexSearcher.Search(query, null, 150);
for(int i=100, i<min(topDocs.totalHits,150); i++) {
    Document doc = indexSearcher.doc(topDocs.scoreDocs[i]);

    // Do something with the doc
}

Don't use the Hits class. It is inefficient and deprecated.



来源:https://stackoverflow.com/questions/1242333/lucene-net-result-subsets

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