我无法获得结果。
这是我到目前为止所得到的:
search_indexes.py
class CompanyIndex(SearchIndex):
text = CharField(document=True, use_template=True)
name = CharField(model_attr='name')
sector = CharField(model_attr='sector')
def get_model(self):
return Company
def index_queryset(self):
return self.get_model().objects.all()
site.register(Company,CompanyIndex)
class CompanySearchForm(ModelSearchForm):
name = forms.CharField(max_length=64, required=False)
sector = forms.MultipleChoiceField(choices=SECTORS_CHOICES, required=False)
def search(self):
# First, store the SearchQuerySet received from other processing.
sqs = super(CompanySearchForm, self).search()
print "fgdgdfgdfgdfg"
if self.is_valid():
# Check to see if a start_date was chosen.
if self.cleaned_data['name']:
print "%s" % self.cleaned_data['name']
sqs = sqs.filter(name__exact=self.cleaned_data['name'])
# Check to see if an end_date was chosen.
if self.cleaned_data['sector']:
sqs = sqs.filter(sector__contains=self.cleaned_data['sector'])
return sqs
和网址:
sqs = SearchQuerySet()
url(r'^search/', SearchView(
template='search/search.html',
form_class=CompanySearchForm,
searchqueryset=sqs,
), name='haystack_search'),
我正在使用haystack文档中的模板。 我看不到任何结果。
我感谢任何帮助
答案 0 :(得分:1)
您应该在:
中创建模板模板\搜索\索引\ APP_NAME \ company_text.txt
什么代表您的可搜索字段CompanyIndex
{{ object.text }}
{{ object.name }}
{{ object.sector }}
无论您在search_index.py中是否存在,都会从索引中搜索您在模板中编写的内容。 以下就足以制作一个索引。
text = CharField(document=True, use_template=True)