org.apache.lucene.search
Class DisjunctionSumScorer

java.lang.Object
  extended by org.apache.lucene.search.Scorer
      extended by org.apache.lucene.search.DisjunctionSumScorer

public class DisjunctionSumScorer
extends Scorer

A Scorer for OR like queries, counterpart of Lucene's ConjunctionScorer. This Scorer implements Scorer.skipTo(int) and uses skipTo() on the given Scorers.


Field Summary
protected  int nrMatchers
          The number of subscorers that provide the current match.
protected  List subScorers
          The subscorers.
 
Constructor Summary
DisjunctionSumScorer(List subScorers)
          Construct a DisjunctionScorer, using one as the minimum number of matching subscorers.
DisjunctionSumScorer(List subScorers, int minimumNrMatchers)
          Construct a DisjunctionScorer.
 
Method Summary
protected  boolean advanceAfterCurrent()
          Advance all subscorers after the current document determined by the top of the scorerQueue.
 int doc()
          Returns the current document number matching the query.
 Explanation explain(int doc)
          Gives and explanation for the score of a given document.
 boolean next()
          Advances to the next document matching the query.
 int nrMatchers()
          Returns the number of subscorers matching the current document.
 float score()
          Returns the score of the current document matching the query.
 boolean skipTo(int target)
          Skips to the first match beyond the current whose document number is greater than or equal to a given target.
 
Methods inherited from class org.apache.lucene.search.Scorer
getSimilarity, score, score
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

subScorers

protected final List subScorers
The subscorers.


nrMatchers

protected int nrMatchers
The number of subscorers that provide the current match.

Constructor Detail

DisjunctionSumScorer

public DisjunctionSumScorer(List subScorers,
                            int minimumNrMatchers)
Construct a DisjunctionScorer.

Parameters:
subScorers - A collection of at least two subscorers.
minimumNrMatchers - The positive minimum number of subscorers that should match to match this query.
When minimumNrMatchers is bigger than the number of subScorers, no matches will be produced.
When minimumNrMatchers equals the number of subScorers, it more efficient to use ConjunctionScorer.

DisjunctionSumScorer

public DisjunctionSumScorer(List subScorers)
Construct a DisjunctionScorer, using one as the minimum number of matching subscorers.

Method Detail

next

public boolean next()
             throws IOException
Description copied from class: Scorer
Advances to the next document matching the query.

Specified by:
next in class Scorer
Returns:
true iff there is another document matching the query.
When this method is used the Scorer.explain(int) method should not be used.
Throws:
IOException

advanceAfterCurrent

protected boolean advanceAfterCurrent()
                               throws IOException
Advance all subscorers after the current document determined by the top of the scorerQueue. Repeat until at least the minimum number of subscorers match on the same document and all subscorers are after that document or are exhausted.
On entry the scorerQueue has at least minimumNrMatchers available. At least the scorer with the minimum document number will be advanced.

Returns:
true iff there is a match.
In case there is a match, currentDoc, currentSumScore, and nrMatchers describe the match.
Throws:
IOException
To Do:
Investigate whether it is possible to use skipTo() when the minimum number of matchers is bigger than one, ie. try and use the character of ConjunctionScorer for the minimum number of matchers.

score

public float score()
            throws IOException
Returns the score of the current document matching the query. Initially invalid, until next() is called the first time.

Specified by:
score in class Scorer
Throws:
IOException

doc

public int doc()
Description copied from class: Scorer
Returns the current document number matching the query. Initially invalid, until Scorer.next() is called the first time.

Specified by:
doc in class Scorer

nrMatchers

public int nrMatchers()
Returns the number of subscorers matching the current document. Initially invalid, until next() is called the first time.


skipTo

public boolean skipTo(int target)
               throws IOException
Skips to the first match beyond the current whose document number is greater than or equal to a given target.
When this method is used the explain(int) method should not be used.
The implementation uses the skipTo() method on the subscorers.

Specified by:
skipTo in class Scorer
Parameters:
target - The target document number.
Returns:
true iff there is such a match.
Throws:
IOException

explain

public Explanation explain(int doc)
                    throws IOException
Gives and explanation for the score of a given document.

Specified by:
explain in class Scorer
Parameters:
doc - The document number for the explanation.
Throws:
IOException
To Do:
Show the resulting score. See BooleanScorer.explain() on how to do this.


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.