我使用Haystack和elasticsearch后端。 当我进行查询时,我得不到任何结果。 我还能尝试什么? 我真的被卡住了。 任何帮助赞赏! :)
这是我的代码
view.py
class ActressSearchView(SearchView):
template = 'search/search.html'
form_class = SearchForm
def get_queryset(self):
queryset = super(ActressSearchView, self).get_queryset()
q = queryset.order_by('name','release_date')
return q
def get_context_data(self, *args, **kwargs):
context = super(ActressSearchView, self).get_context_data(*args, **kwargs)
return context
url.py
url(r'^search/?$', ActressSearchView.as_view(), name='search'),
search_indexes.py
class EnActressIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.EdgeNgramField(document=True, use_template=True)
en_name = indexes.CharField(model_attr='name')
def get_model(self):
return EnActress
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return self.get_model().objects.all()
class EnMovielistIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.EdgeNgramField(document=True, use_template=True)
content_ID = indexes.CharField(model_attr='content_ID')
release_date = indexes.CharField(model_attr='release_date')
actress = indexes.CharField(model_attr='actress')
label = indexes.CharField(model_attr='label')
def get_model(self):
return EnMovielist
def index_queryset(self, using=None):
return self.get_model().objects.all()