QueryScorerpublic class QueryScorer extends Object implements Scorer{@link Scorer} implementation which scores text fragments by the number of unique query terms found.
This class uses the {@link QueryTermExtractor} class to process determine the query terms and
their boosts to be used. |
Fields Summary |
---|
TextFragment | currentTextFragment | HashSet | uniqueTermsInFragment | float | totalScore | float | maxTermWeight | private HashMap | termsToFind |
Constructors Summary |
---|
public QueryScorer(Query query)
this(QueryTermExtractor.getTerms(query));
| public QueryScorer(Query query, String fieldName)
this(QueryTermExtractor.getTerms(query, false,fieldName));
| public QueryScorer(Query query, IndexReader reader, String fieldName)
this(QueryTermExtractor.getIdfWeightedTerms(query, reader, fieldName));
| public QueryScorer(WeightedTerm[] weightedTerms)
termsToFind = new HashMap();
for (int i = 0; i < weightedTerms.length; i++)
{
WeightedTerm existingTerm=(WeightedTerm) termsToFind.get(weightedTerms[i].term);
if( (existingTerm==null) ||(existingTerm.weight<weightedTerms[i].weight) )
{
//if a term is defined more than once, always use the highest scoring weight
termsToFind.put(weightedTerms[i].term,weightedTerms[i]);
maxTermWeight=Math.max(maxTermWeight,weightedTerms[i].getWeight());
}
}
|
Methods Summary |
---|
public void | allFragmentsProcessed()
//this class has no special operations to perform at end of processing
| public float | getFragmentScore()
return totalScore;
| public float | getMaxTermWeight()
return maxTermWeight;
| public float | getTokenScore(org.apache.lucene.analysis.Token token)
String termText=token.termText();
WeightedTerm queryTerm=(WeightedTerm) termsToFind.get(termText);
if(queryTerm==null)
{
//not a query term - return
return 0;
}
//found a query term - is it unique in this doc?
if(!uniqueTermsInFragment.contains(termText))
{
totalScore+=queryTerm.getWeight();
uniqueTermsInFragment.add(termText);
}
return queryTerm.getWeight();
| public void | startFragment(TextFragment newFragment)
uniqueTermsInFragment = new HashSet();
currentTextFragment=newFragment;
totalScore=0;
|
|