You do not have to adapt the scoring algorithm (which implements tf-idf btw).
If you just want to integrate the number of views into the scoring, you can βincreaseβ the search document before adding it to the index, for example:
$doc = new Zend_Search_Lucene_Document(); $boostFactor = 0.1; $doc->boost = (float)$numberOfVotes * $boostFactor; // .. $index->addDocument($doc); $index->commit();
The increase factor in this example is not significant, since you have only one increase criterion. If you want to increase non-linearity, you can also use exp or sqrt on $ numberOfVotes.
But another question:
Why not use ElasticSearch (or another search engine) in the first place?
ElasticSearch, for example. is more powerful and faster than the PHP implementation of Zend Lucene. In addition, it is very easy to connect a scoring mechanism, for example. http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query.html You can use a PHP client, for example Elastica with it.
source share