Django全文搜索的相关性 [英] Django full text search order by relevance

查看:70
本文介绍了Django全文搜索的相关性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Django查询过滤器__search执行全文搜索,例如

I am using the Django query filter __search to perform a full text search e.g

MyModel.objects.filter(title__search = 'some title')

如何根据相关性进行排序,目前看来

How do I get it to order by relevance, as currently it seems to be ordering alphabetically?

具体来说,我希望标题为某些标题的搜索结果首先出现在具有标题不同但包含一些标题

Specifically I would like search results where the title was some title to appear first before something that had the title a different but contains some title.

编辑:

我注意到的是,在MyModel的模型定义上,我有:

What I've noticed is that on the model definition for MyModel I have:

class Meta:
    ordering = ['title']

如果我删除了该内容,则排序变得正确,即按相关性排序。因此,有什么办法可以将其保留在模型定义中,使其在其他地方有用,但随后在我的查询中告诉它忽略它?

If I remove this then the ordering becomes correct i.e. sorted by relevance. So is there a way I can leave this in the model definition as its useful elsewhere but then on my query tell it to ignore it?

推荐答案

尝试: Model.objects.all()。order_by()。search()-调用没有任何参数的order_by根本没有排序

除此之外:我将第二次提出卡尔对Haystack的建议,特别是因为它允许进行更复杂的操作,例如阻止(跳舞将匹配跳舞,跳舞者和跳舞),刻面(向我显示用户&每个搜索结果的点击数),获取与您当前正在显示的对象相似的对象,等等。当我上次尝试Whoosh时,它是不稳定的(即在索引编制过程中崩溃了),但是花费了相当短的时间是时候启动Solr,了不起。

Beyond that: I'll second Carl's recommendation of Haystack, particularly since that allows more complicated things like stemming ("dance" would match "dances" ,"dancers", and "dancing"), faceting ("Show me user & number of hits for each search result"), getting objects which are similar to the one you're currently displaying, etc. When I last tried Whoosh it was unstable (i.e. crashed during indexing) but it took a rather short period of time to fire up Solr, which is great.

这篇关于Django全文搜索的相关性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆