如何在 Sphinx 搜索中给予较新的文章更多权重?
我在 django 网站上有一个 Sphinx 搜索,运行得很好。它可以为各种查询找到出色的匹配。我希望能够提高新结果的排名。很多时候,多年以前的文章的排名会比全新的文章更高。较旧的文章更频繁地包含搜索词,因此相关性较高,但新文章仍然非常相关,因此我希望它们首先出现。
我尝试阅读有关权重的 Sphinx 文档,但它非常令人困惑,并且充满了我不太理解的术语。我想让搜索基本保持原样,我只是想稍微提高最近 pub_dates 的结果的排名。
I have a Sphinx search on a django site that is running very well. 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 SPH_SORT_EXPR 您可以通过算术表达式更改排序,例如:
$cl->SetSortMode ( SPH_SORT_EXPR,
"@weight + IF(pub_date > strtotime('2011-01-01), 50, 0) );
在这个表达式中,从 2011 年 1 月 1 日开始发表的文章将获得 +50 的权重。
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.
这是行不通的,因为使用绝对值很难预测结果。例如,两个帖子的 id 分别为 100 和 id 99000,但 id 100 的权重非常好,而 id 99000 的权重非常差,那么 id 99000 就会上升。
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" );
这为您提供了一个斜坡 - 越新,权重越大。只需执行@id * 2
即可使效果加倍,或执行/ 2
来减弱效果。$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.