FileDocCategorySizeDatePackage
ConjunctionScorer.javaAPI DocApache Lucene 2.1.04045Wed Feb 14 10:46:40 GMT 2007org.apache.lucene.search

ConjunctionScorer

public class ConjunctionScorer extends Scorer
Scorer for conjunctions, sets of queries, all of which are required.

Fields Summary
private Scorer[]
scorers
private int
length
private int
first
private int
last
private boolean
firstTime
private boolean
more
private float
coord
Constructors Summary
public ConjunctionScorer(Similarity similarity)


     
    super(similarity);
  
Methods Summary
final voidadd(org.apache.lucene.search.Scorer scorer)

    if (length >= scorers.length) {
      // grow the array
      Scorer[] temps = new Scorer[scorers.length * 2];
      System.arraycopy(scorers, 0, temps, 0, length);
      scorers = temps;
    }
    last += 1;
    length += 1;
    scorers[last] = scorer;
  
private booleandoNext()

    while (more && scorers[first].doc() < scorers[last].doc()) { // find doc w/ all clauses
      more = scorers[first].skipTo(scorers[last].doc());      // skip first upto last
      last = first; // move first to last
      first = (first == length-1) ? 0 : first+1;
    }
    return more;                                // found a doc with all clauses
  
public intdoc()

 return scorers[first].doc(); 
public org.apache.lucene.search.Explanationexplain(int doc)

    throw new UnsupportedOperationException();
  
private voidinit(boolean initScorers)

    //  compute coord factor
    coord = getSimilarity().coord(length, length);
   
    more = length > 0;

    if(initScorers){
      // move each scorer to its first entry
      for (int i = 0, pos = first; i < length; i++) {
        if (!more) break; 
        more = scorers[pos].next();
        pos = (pos == length-1) ? 0 : pos+1;
      }
      // initial sort of simulated list
      if (more) 
        sortScorers();
    }

    firstTime = false;
  
public booleannext()

    if (firstTime) {
      init(true);
    } else if (more) {
      more = scorers[last].next();                   // trigger further scanning
    }
    return doNext();
  
public floatscore()

    float sum = 0.0f;
    for (int i = 0; i < length; i++) {
      sum += scorers[i].score();
    }
    return sum * coord;
  
public booleanskipTo(int target)

    if(firstTime) {
      init(false);
    }
    
    for (int i = 0, pos = first; i < length; i++) {
      if (!more) break; 
      more = scorers[pos].skipTo(target);
      pos = (pos == length-1) ? 0 : pos+1;
    }
    
    if (more)
      sortScorers();                              // re-sort scorers
    
    return doNext();
  
private voidsortScorers()

    // squeeze the array down for the sort
    if (length != scorers.length) {
      Scorer[] temps = new Scorer[length];
      System.arraycopy(scorers, 0, temps, 0, length);
      scorers = temps;
    }
    
    // note that this comparator is not consistent with equals!
    Arrays.sort(scorers, new Comparator() {         // sort the array
        public int compare(Object o1, Object o2) {
          return ((Scorer)o1).doc() - ((Scorer)o2).doc();
        }
      });
   
    first = 0;
    last = length - 1;