At least for version 1.4.3 a can confirm, that DIGYs approach works perfectly 
since I have got it in production for quite a long time now. I don't expect 
that this behaviour has changed much.
 
Here's the code I use for this:
 
struct SearchResult
{
  public float Score; public int DocId; public Document Doc;
 
  public SearchResult(float score, int docId, Document doc) { Score=score; 
DocId=docId; Doc=doc; }
}
 
ArrayList Search(IndexSearcher indexSearcher, Query query, Filter filter, Sort 
sort, int startIndex, int count)
{
 if (startIndex < 0) throw new ArgumentOutOfRangeException("startIndex must be 
>= 0");
 Hits hits = indexSearcher.Search(query, filter, sort);
 if (count == -1) count = hits.Length();
 int maxIndex = Math.Min(startIndex + count - 1, hits.Length() - 1);
 ArrayList resultRange = new ArrayList();
 for (int i = startIndex; i <= maxIndex; i++)
 {
  resultRange.Add(new SearchResult(hits.Score(i), hits.Id(i), hits.Doc(i)));
 }
 return resultRange;
}

-Erich

________________________________

From: Digy [mailto:[EMAIL PROTECTED]
Sent: Mon 2008-03-17 20:32
To: lucene-net-user@incubator.apache.org
Subject: RE: lucene.net query



Hi Sudhanya,

I think a little bit different than Michael. Iterating over all hits is a slow 
process.
Therefore repeating the search for each "page" and fetching the results(say 10 
or 20) like below
may result in a faster response to the user.
(I think no one retrieves all of the result pages of a google search).

pageNum=3;
numDocs = 10; //Result for one "page"
startOffset = pageNum*numDocs;

TopDocs result = indexSearcher.Search(query, null, startOffset + numDocs);
for (int i = startOffset; i < startOffset+ numDocs; i++)
{
        Document doc = indexSearcher.Reader.Document(result.scoreDocs[i].doc));
        ......
}



DIGY



-----Original Message-----
From: Michael Garski [mailto:[EMAIL PROTECTED]
Sent: Monday, March 17, 2008 7:03 PM
To: lucene-net-user@incubator.apache.org
Subject: RE: lucene.net query

Sudhanya,

It sounds like you just want a specific 'page' of the results, rather than the 
entire set, correct?

Lucene does not have any built in functionality for this, and I would suggest 
persisting the results after a query is executed and then paging through them.

Michael

-----Original Message-----
From: Sudhanya Chatterjee [mailto:[EMAIL PROTECTED]
Sent: Monday, March 17, 2008 7:15 AM
To: lucene-net-user@incubator.apache.org
Subject: lucene.net query

Hi,



In our application we are using WildcardQuery to fetch the results.

Is it possible to get specific range of results?

For example -

            Search results contain 100 records.

            We want only the result from 11th record till 20th record.

            Is it possible to do this without iterating through the full
result set?

            OR

            Is it possible to fire a query where we can specify the start
and the number of records required?



Thanks,

Sudhanya


DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the 
property of Persistent Systems Ltd. It is intended only for the use of the 
individual or entity to which it is addressed. If you are not the intended 
recipient, you are not authorized to read, retain, copy, print, distribute or 
use this message. If you have received this communication in error, please 
notify the sender and delete all copies of this message. Persistent Systems 
Ltd. does not accept any liability for virus infected mails.



Reply via email to