プロジェクトの 1 つで、 pyelasticsearch v0.3を使用してdjango-haystack v2.0.0を実行しています。リスト テンプレートをレンダリングするがあり、結果のフィルタリングを統合したいと考えています。検索は正常に実行されますが、使用しているフィルターがまったく機能していません。次のフィルターを使用していますが、結果リストに違いがあるようには見えません。SearchView__contains__lte__gte
たとえば、SearchView検索語に基づいて からレンダリングされた 10 件の結果があるとします。同じテンプレートに、(GETメソッドを使用する) フィルターフォームがあり、同じを呼び出しますSearchView。SearchView の下に、_filter_results次のように定義されたカスタム プライベート メソッドがあります。
def _filter_results(results, filters):
"""
This method would return the filtered search results, based on
the filters applied by a user.
"""
for item in filters:
if item == 'location':
results = results.filter(locations__contains=filters[item])
print results
if item == 'age_min':
results = results.filter(workex_min__gte=filters[item])
if item == 'age_max':
results = results.filter(workex_max__lte=filters[item])
return results
ここで、次のように結果をテンプレートに渡します。
context {'results' : _filter_results(self.results, self.result_filters)}
self.result_filtersSearchViewのメソッドで設定したフィルターの辞書で、次の__call__ようになります。
{
'location' : request.GET.get('location'),
'age_min' : request.GET.get('age_min'),
'age_max' : request.GET.get('age_max'),
}
エラーは発生しません。各フィルター値が_filter_resultsメソッドに渡されていることを再確認しました。しかし、結果はまだ同じままです。
10 エントリの結果リストで、場所が含まれていない場所でフィルタリングしようとすると、同じ 10 エントリの結果が返されます。何が原因でしょうか?