lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tony Schwartz" <>
Subject RE: Implementing paging functionality in lucene
Date Sun, 24 Jul 2005 16:33:46 GMT
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
"We're going to need a lot more cowbell."

-----Original Message-----
From: Harini Raghavan [] 
Sent: Sunday, July 24, 2005 12:21 PM
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 method, the bitset.get(doc) is
returning false for all the other documents and so they are not added to the
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 =, new PageFilter(0,20));
  "Found " + hits.length() + " document(s) that
matched query '" + query + "':");
            results = indexSearchUtil.populateDocumentInfoView(hits,
      } 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++) {
        return result;

Any suggestion would be greatly appreciated.

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message