[pylucene-dev] extend Similarity -- but only want to overide one func: lengthNorm()

Andi Vajda vajda at osafoundation.org
Thu Mar 8 10:28:46 PST 2007


On Thu, 8 Mar 2007, Andi Vajda wrote:

>> Is it possible extend the Similarity class via
>> PyLucene but only to override one function, namely
>> lengthNorm()?
>> 
>> I've seen the examples in ScoreTest.py and
>> test_similarity.py, and they both take over *all*
>> functions, but i would like to just get whatever
>> default behaviour i was getting before via Similarity,
>> except for i need to tweak lengthNorm a bit.
>> 
>
> The Java Lucene Similarity class is abstract. PythonSimilarity, the way to 
> implement it in python directly extends it and hence requires all abstract 
> Similarity methods to be implemented.
>
> This could be done, however, by making it possible to use a 
> SimilarityDelegator instance (currently missing in PyLucene) with a python 
> object implementing only certain Similarity methods. 
> http://lucene.apache.org/java/docs/api/org/apache/lucene/search/SimilarityDelegator.html
>
> More about this in a bit...

I added support for the Lucene SimilarityDelegator class giving it an extra 
constructor argument, a python similarity implementation that may be partial.

For example:

     class zeroTf(object):
         def tf(self, freq):
             return 0.0

     similarity = SimilarityDelegator(DefaultSimilarity(), zeroTf())

This is checked into svn.

Andi..



More information about the pylucene-dev mailing list