我正在将Haystack与ElasticSearch一起使用,以搜索我网站上用户的文档。用户彼此“关注”,我希望我关注的用户的匹配文档在其他用户的匹配文档之前显示。在每个类别中,我想根据默认分数将排序留给Haystack。
class DocumentIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
title = indexes.CharField(model_attr="title", boost=3.0)
follow = indexes.MultiValueField()
def search(self):
sqs = self.searchqueryset.auto_query(self.cleaned_data['q'])
friend_results = sqs.filter(friends=self.cleaned_data['username'])
other_results = sqs.exclude(friends=self.cleaned_data['username'])
#***** Can I do something like this? ****#
final_query_set = join (friend_results, other_results)
return final_query_set
谢谢您的帮助。
最佳答案
final_query_set = friend_results | other results
我认为这就是您想要的。
关于elasticsearch - 加入Haystack SearchQuerySets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17537125/