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
ご協力ありがとうございました。