FileDocCategorySizeDatePackage
ConjunctionScorer.javaAPI DocApache Lucene 1.4.33735Tue May 11 19:18:04 BST 2004org.apache.lucene.search

ConjunctionScorer

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

Fields Summary
private LinkedList
scorers
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)

    scorers.addLast(scorer);
  
private booleandoNext()

    while (more && first().doc() < last().doc()) { // find doc w/ all clauses
      more = first().skipTo(last().doc());      // skip first upto last
      scorers.addLast(scorers.removeFirst());   // move first to last
    }
    return more;                                // found a doc with all clauses
  
public intdoc()

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

    throw new UnsupportedOperationException();
  
private org.apache.lucene.search.Scorerfirst()

 return (Scorer)scorers.getFirst(); 
private voidinit()

    more = scorers.size() > 0;

    // compute coord factor
    coord = getSimilarity().coord(scorers.size(), scorers.size());

    // move each scorer to its first entry
    Iterator i = scorers.iterator();
    while (more && i.hasNext()) {
      more = ((Scorer)i.next()).next();
    }
    if (more)
      sortScorers();                              // initial sort of list

    firstTime = false;
  
private org.apache.lucene.search.Scorerlast()

 return (Scorer)scorers.getLast(); 
public booleannext()

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

    float score = 0.0f;                           // sum scores
    Iterator i = scorers.iterator();
    while (i.hasNext())
      score += ((Scorer)i.next()).score();
    score *= coord;
    return score;
  
public booleanskipTo(int target)

    Iterator i = scorers.iterator();
    while (more && i.hasNext()) {
      more = ((Scorer)i.next()).skipTo(target);
    }
    if (more)
      sortScorers();                              // re-sort scorers
    return doNext();
  
private voidsortScorers()

    // move scorers to an array
    Scorer[] array = (Scorer[])scorers.toArray(new Scorer[scorers.size()]);
    scorers.clear();                              // empty the list

    // note that this comparator is not consistent with equals!
    Arrays.sort(array, new Comparator() {         // sort the array
        public int compare(Object o1, Object o2) {
          return ((Scorer)o1).doc() - ((Scorer)o2).doc();
        }
        public boolean equals(Object o1, Object o2) {
          return ((Scorer)o1).doc() == ((Scorer)o2).doc();
        }
      });
    
    for (int i = 0; i < array.length; i++) {
      scorers.addLast(array[i]);                  // re-build list, now sorted
    }