我已经建立了几个搜索索引模型。现在,我有一个页面,我只想在Haystack中的两个模型中进行搜索:“手稿”和“页面”。我不太了解Haystack的文档。目前,查询仍在所有已建立索引的模型中运行。我应该如何设置views.py和index.py?预先感谢。
搜索手稿和页面的索引:
class PageIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
uniqueID = indexes.CharField(model_attr='id_tei')
manuscript = indexes.CharField(model_attr='Manuscript_id', null=True, faceted=True) #this isn't in the database...??
fulltext = indexes.CharField(model_attr='fulltext')
modeltype = indexes.CharField(model_attr='get_type', null=True)
def get_model(self):
return Page
def get_type(self):
return 'Page'
class ManuscriptIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
uniqueID = indexes.CharField(model_attr='id_tei')
title = indexes.CharField(model_attr='title', null=True)
person_id = indexes.CharField(model_attr='person_id', null=True, faceted=True)
date = indexes.CharField(model_attr='date', null=True, faceted=True)
type_of_Manuscript = indexes.CharField(model_attr='type_of_Manuscript', null=True, faceted=True)
call_no = indexes.CharField(model_attr='call_no', null=True)
modeltype = indexes.CharField(model_attr='get_type', null=True)
def get_model(self):
return Manuscript
def get_type(self):
return 'Manuscript'
views.py搜索页面:
def search(request):
if search:
clean_query = SearchQuerySet().query.clean(user_query)
sqs = SearchQuerySet().models(Page, Manuscript).filter(SQ(content=clean_query))
return render(request, 'search/search.html')
urls.py:
urlpatterns = [
...
path('search/',include('haystack.urls')),
...
]