lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Harini Raghavan" <harini.ragha...@insideview.com>
Subject Implementing paging functionality in lucene
Date Sun, 24 Jul 2005 16:20:41 GMT
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: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message