FileDocCategorySizeDatePackage
ReadTask.javaAPI DocApache Lucene 2.2.04258Sat Jun 16 22:20:58 BST 2007org.apache.lucene.benchmark.byTask.tasks

ReadTask

public abstract class ReadTask extends PerfTask
Read index (abstract) task. Sub classes implement withSearch(), withWarm(), withTraverse() and withRetrieve() methods to configure the actual action.

Note: All ReadTasks reuse the reader if it is already open. Otherwise a reader is opened at start and closed at the end.

Other side effects: none.

Fields Summary
Constructors Summary
public ReadTask(org.apache.lucene.benchmark.byTask.PerfRunData runData)

    super(runData);
  
Methods Summary
public intdoLogic()

    int res = 0;
    boolean closeReader = false;
    
    // open reader or use existing one
    IndexReader ir = getRunData().getIndexReader();
    if (ir == null) {
      Directory dir = getRunData().getDirectory();
      ir = IndexReader.open(dir);
      closeReader = true;
      //res++; //this is confusing, comment it out
    }
    
    // optionally warm and add num docs traversed to count
    if (withWarm()) {
      Document doc = null;
      for (int m = 0; m < ir.maxDoc(); m++) {
        if (!ir.isDeleted(m)) {
          doc = ir.document(m);
          res += (doc==null ? 0 : 1);
        }
      }
    }
    
    if (withSearch()) {
      res++;
      IndexSearcher searcher = new IndexSearcher(ir);
      QueryMaker queryMaker = getQueryMaker();
      Query q = queryMaker.makeQuery();
      Hits hits = searcher.search(q);
      //System.out.println("searched: "+q);
      
      if (withTraverse() && hits!=null) {
        int traversalSize = Math.min(hits.length(), traversalSize());
        if (traversalSize > 0) {
          boolean retrieve = withRetrieve();
          for (int m = 0; m < hits.length(); m++) {
            int id = hits.id(m);
            res++;
            if (retrieve) {
              res += retrieveDoc(ir, id);
            }
          }
        }
      }
      
      searcher.close();
    }
    
    if (closeReader) {
      ir.close();
    }
    return res;
  
public abstract org.apache.lucene.benchmark.byTask.feeds.QueryMakergetQueryMaker()
Return query maker used for this task.

protected intretrieveDoc(org.apache.lucene.index.IndexReader ir, int id)

    return (ir.document(id) == null ? 0 : 1);
  
public inttraversalSize()
Specify the number of hits to traverse. Tasks should override this if they want to restrict the number of hits that are traversed when {@link #withTraverse()} is true. Must be greater than 0. Read task calculates the traversal as: Math.min(hits.length(), traversalSize())

return
Integer.MAX_VALUE

    return Integer.MAX_VALUE;
  
public abstract booleanwithRetrieve()
Return true if, with search & results traversing, docs should be retrieved.

public abstract booleanwithSearch()
Return true if search should be performed.

public abstract booleanwithTraverse()
Return true if, with search, results should be traversed.

public abstract booleanwithWarm()
Return true if warming should be performed.