[pylucene-dev] why isn't my custom Similarity object changing
the behavior?
Andi Vajda
vajda at osafoundation.org
Mon Mar 19 10:15:51 PST 2007
On Thu, 15 Mar 2007, Ofer Nave wrote:
> I'm just now starting to play with the scoring algorithm. The first change
> I want to make is to have the score ignore term frequency. I created this
> test script to validate my understanding of the API, but my custom
> Similarity class doesn't seem to affect the tf values in the output, and I
> can't figure out why. I've looked at the docs, the scoring page on the
> lucene site, and various archived posts, and I don't see anything I've done
> wrong.
>
> The print statement in tf() was to test if the overridden method is even
> getting called. It's not.
>
> class SimilaritySansTF(PyLucene.DefaultSimilarity):
> def tf(freq):
> print 'freak out!'
> return 1
>
Because PyLucene wraps Lucene classes, you cannot extend them that way.
Your SimilaritySansTF class extends the wrapper, not the actual Lucene class.
There are examples in samples/LuceneInAction and in tests that show how to
implement a complete custom Similarity class. Also, I very recently added
support for Lucene's SimilarityDelegator class which makes it possible to use
a partial Similarity implementation delegating the remaining calls to another
complete implementation. To use this class, you need to build PyLucene form
svn sources, normally a non-trivial task. I should have binaries up for the
usual OS I have access to in the near future.
Andi..
More information about the pylucene-dev
mailing list