views:

39

answers:

1

Hi,

I am currently using Zend_Search_Lucene to index and search a number of documents currently at around a 1000 or so. What I would like to do is change how the engine scores hits on a document, from the current default.

Zend_Search_Lucene scores on the frequency of number of hits within a document, so a document that has 10 matches of the word PHP will score higher than a document with only 3 matches of PHP. What I am trying to do is pass a number of key words and score depending on the hits of those keywords. e.g.

I pass 5 key words say,PHP, MySQL, Javascript, HTML and CSS that I search against the index. One document has 3 matches to those key words and one document has all 4 matches, the 4 matches scores the highest. The number of instances of those words in the document do not concern me.

Now I've had a quick look at Zend_Search_Lucene_Search_Similarity however I have to confess that I am not sure (or that bright) to know how to use this to achieve what I am after.

Is what I want to do possible using Lucene or is there a better solution out there?

+1  A: 

For what I've understood in the Zend_Search_Lucene_Search_Similarity section of the manual, I'd start by extending the default similarity class to override the tf (term frequency) method so that it doesn't alter the score:

class MySimilarity extends Zend_Search_Lucene_Search_Similarity {    
    public function tf($freq) {
        return 1.0; // overriding default sqrt($freq);
    }
}

This way the number of matches shouldn't be taken into account. Do you think this would be enough?

Then, set it to be the default similarity algorithm before indexing:

Zend_Search_Lucene_Search_Similarity::setDefault(new MySimilarity());
nuqqsa
This has improved the scoring of the documents somewhat, but there is still a bit to go, which I think can also be helped with a bit of boosting of key terms. Thanks again.
Grant Collins