views:

143

answers:

2

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  A: 

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.

KenE
+2  A: 

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.

itsadok