lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Granroth, Neal V." <neal.granr...@thermofisher.com>
Subject RE: what is the best way to limit results coming back from a lucene search
Date Wed, 29 Aug 2007 20:30:02 GMT
One way to do this is to use the Searcher method:

   TopDocs Search(Query query, Filter filter, int n)

The value "n" specifies the maximum number of "hits" you want returned.

A null can be passed in as the filter if you do not wish to use one.

The returned "hits" are retrieved through the TopDocs object, as in this example which finds
the first 10 documents with field "title" containing the word "test".

IndexSearcher s = new IndexSearcher(index-path);
TopDocs td = s.Search( new TermQuery("title","test"), (Filter)null, 10);
int countReturned = td.scoreDocs.Length;
for(int ii=0; ii<countReturned; ++ii)
{
   Document d = s.Doc( td.scoreDocs[ii].doc );

   ...

}

s.Close();


Hope this helps.

-- Neal

Mime
View raw message