开发者

How do I give more weight to newer articles in Sphinx search?

I have a Sphinx search on a django site that is running very we开发者_开发技巧ll. It finds excellent matches for all sorts of queries. I would like to be able to give a boost in ranking to newer results. Quite often articles that are many years old will rank higher than brand new articles. The older articles contain the search term more often, so have higher relevancy, but the new articles are still very relevant, so I would like them to appear first.

I tried to read the Sphinx documentation about weighting, but it is incredibly confusing and filled with terminology that I don't really understand. I want to keep the search mostly the same as it is, I just want to give a slight boost in ranking to results with more recent pub_dates.


Using SPH_SORT_EXPR you can change sorting by an arithmetic expression, like:

$cl->SetSortMode ( SPH_SORT_EXPR, "@weight + IF(pub_date > strtotime('2011-01-01), 50, 0) );

In this expression, articles which was published starting from 1 Jan 2011 will gain +50 to the weight.


$cl->SetSortMode ( SPH_SORT_EXPR, "@id" ); this gives you a ramp--the more recent, the more weight. Simply do @id * 2 to double the effect or / 2 to dampen it.

This wouldn't work, because using absolute values it is hard to predict the results. For example two posts with id 100 and id 99000 respective, but with very good weight for id 100 and very bad weight for id 99000 will up the id 99000.


$cl->SetSortMode ( SPH_SORT_EXPR, "@id" ); this gives you a ramp--the more recent, the more weight. Simply do @id * 2 to double the effect or / 2 to dampen it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜