2016-01-30 37 views
0

我想在搜索列表中的所有結果 -通過Elasticsearch中的其他數據進行排序。可能嗎?

# [ [num, pk], [1, 34], [2, 3147] ...] 
# num = [0, 1, 2, ... 7] 
pks = [34, 3147,..., 1264] 

我想搜索哪裏related__in=pks,但像他這樣。 第一個.filter(related=pk[0]),然後.filter(related=pk[1]) ...並將結果連接到單個查詢。

SO:

我可以添加一些申請/數據searchqueryset通過它以後排序?

或者也許連接許多searchquerysets到一個?

回答

0

你所描述的是一個Haystack MultiValueField允許被搜索引擎查詢多對多關係,就像你在你的答案暗示。

這是demonstrated in the documentation like so

class NoteIndex(SearchIndex, indexes.Indexable): 
    text = CharField(document=True, use_template=True) 
    author = CharField(model_attr='user') 
    categories = MultiValueField() 

有關如何有效地查詢這個領域,see this related question細節。

+0

我需要儘可能多值,但排序爲列表。首先與第一個PK有關的所有項目,然後是第二個,第三個... – ubombi

相關問題