Don't do that.  Don't use a filter for paging.  Just use the Hits object and
get from it only the records applicable for that page.

Tony Schwartz
[EMAIL PROTECTED]
"We're going to need a lot more cowbell."




-----Original Message-----
From: Harini Raghavan [mailto:[EMAIL PROTECTED] 
Sent: Sunday, July 24, 2005 12:21 PM
To: java-user@lucene.apache.org
Subject: Implementing paging functionality in lucene

Hi All,

I am trying to add paging functionality while using lucene search. I have
created a PageFilter what takes in the current page num and the number of
records as input and invoking the IndexSearcher passing the a Boolean Query
object and the PageFilter. The search returns around 1000 records when
invoked without the PageFilter, but with the PageFilter, it returns only 6
records. I did some debugging and realised that the in the
org.apache.lucene.search.IndexSearcher.search method, the bitset.get(doc) is
returning false for all the other documents and so they are not added to the
results.
Has someone implemented Paging using filters or tell me if I am missing
something here?

Here is the code :

 public List searchDocuments(DocumentSearchCriteria searchCriteria) throws
ApplicationException {
      List results = new ArrayList();
      String indexLoc = luceneConfig.getIndexDir();
      Directory fsDir = getIndexDirectory(indexLoc, false);
      IndexSearcher searcher = getIndexSearcher(fsDir);

      Query query = indexSearchUtil.getSearchQuery(searchCriteria);
      try {
            Hits hits = searcher.search(query, new PageFilter(0,20));
            logger.info("Found " + hits.length() + " document(s) that
matched query '" + query + "':");
            results = indexSearchUtil.populateDocumentInfoView(hits,
results);
      } catch(Exception e) {
           logger.error("Exception occurred in searchDocuments()");
      }
      return results;
 }

Here is the PageFilter :

public class PageFilter extends Filter {
    private int start;
    private int end;

    public PageFilter(int pageNum, int pageSize) {
        start = pageNum * pageSize;
        end = (pageNum+1) * pageSize;
    }

    public BitSet bits(IndexReader reader) throws IOException {
        BitSet result = new BitSet(reader.maxDoc());
        for(int i=start; (i<end) && (i<result.size()); i++) {
            result.set(i);
        }
        return result;
    }
}

Any suggestion would be greatly appreciated.
Thanks,
Harini


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to