lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Elschot <paul.elsc...@xs4all.nl>
Subject Re: lucene Scorers
Date Fri, 12 Nov 2004 20:01:43 GMT
On Friday 12 November 2004 20:48, Ken McCracken wrote:
> Hi,
> 
> I am looking at the Similarity class overview, and wondering if I can
> replace the SUM operator with a MAX operator, or any other operator
> (across the terms in a query).
> 
> For example, if I search for "car OR automobile", a BooleanScorer is
> used to add the values from each subexpression together.  In the
> BooleanScorer from lucene_1_4_final, in the inner class Collector, we
> have in the collect(...) method, the line
> 
>      bucket.score += score;			  // increment score
> 
> that I may want replace with a MAX operator such as 
> 
>      if (score > bucket.score) bucket.score = score;        // take the max
> 
> I may also want to keep track of both the max and the sum, by
> extending the inner class Bucket.
> 
> Do you have any suggestions on how to implement such a change? 
> Ideally, I would like to have the ability to define my choice of
> scoring algorithm at search time (at run time), and use the Lucene SUM
> scorer for some searches, and the MAX scorer for other searches.
> 
> Thanks for you help.
> 
> -Ken
> 
> PS.  The code I'm talking about falls in the follwoing area, for my
> example search "car OR automobile".  If I walk the code during search,
> I see that the BooleanScorer$Collector is created by the Weight that
> was just created, in BooleanQuery$BooleanWeight.scorer(...), as it
> adds the subscorers for each of the terms in the BooleanScorer.  When
> that collector is asked to collect(...), its bucketTable is filled in.
>  Since the collectors for each of the terms use the same bucketTable,
> if the document already appears in the bucketTable, then it's score is
> added to implement a SUM operator.

SInce you are that far already, you can (in reverse order):
- replace the BooleanScorer by another one that takes the max
 instead of summing.
- replace the weight to return that scorer.
- replace the BooleanQuery to return that weight.
- override QueryParser.getBooleanQuery() to return that query
 in the cases you want, that is when all clauses are optional.

"replace" usually means "inherit from" in new code.
When you need more info on this, try lucene-dev.

Regards,
Paul Elschot.


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org


Mime
View raw message