org.weborganic.flint.search
Class DocumentCounter

java.lang.Object
  extended by org.apache.lucene.search.Collector
      extended by org.weborganic.flint.search.DocumentCounter

public final class DocumentCounter
extends Collector

Simply counts the number of documents in search results.

Typical usage:

  // creates a document counter
  DocumentCounter counter = new DocumentCounter();

  // make a search
  searcher.search(query, counter);

  // get the final count
  int numberOfDocuments = counter.getCount();
 


Constructor Summary
DocumentCounter()
          Creates a new document counter.
 
Method Summary
 boolean acceptsDocsOutOfOrder()
          Accept documents out of order - the order is irrelevant when counting.
 void collect(int doc)
          Increase the document count.
 int getCount()
          Returns the number of documents counted after a search.
 void reset()
          Resets this document counter for reuse by resetting the count to zero.
 void setNextReader(IndexReader reader, int docbase)
          Does nothing - the scorer is irrelevant when counting documents.
 void setScorer(Scorer scorer)
          Does nothing - the scorer is irrelevant when counting documents.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DocumentCounter

public DocumentCounter()
Creates a new document counter.

Method Detail

setScorer

public void setScorer(Scorer scorer)
Does nothing - the scorer is irrelevant when counting documents.

Specified by:
setScorer in class Collector
Parameters:
scorer - the scorer.

acceptsDocsOutOfOrder

public boolean acceptsDocsOutOfOrder()
Accept documents out of order - the order is irrelevant when counting.

Specified by:
acceptsDocsOutOfOrder in class Collector
Returns:
always true.

collect

public void collect(int doc)
Increase the document count.

Specified by:
collect in class Collector
Parameters:
doc - the position of the Lucene Document in the index

setNextReader

public void setNextReader(IndexReader reader,
                          int docbase)
Does nothing - the scorer is irrelevant when counting documents.

Specified by:
setNextReader in class Collector
Parameters:
reader - the next index reader
docbase - used to re-base document ids for the index.

getCount

public int getCount()
Returns the number of documents counted after a search.

Returns:
the number of documents counted after a search.

reset

public void reset()
Resets this document counter for reuse by resetting the count to zero.