0
我按照入門指南,但是當我運行manage.py rebuild_index
時,似乎沒有我的模型被編入索引。運行rebuild_index時沒有創建索引
當我嘗試在/搜索來搜索,我沒有得到任何結果,這在日誌中:
Problem accessing /solr/select/. Reason: no field name specified in query and no defaultSearchField defined in schema.xml
這裏是我的應用程序的search_indexes.py
。它比指南的模型稍微複雜一點,所以也許這就是它不起作用的原因。
import datetime
from myproject.apps.lead import Lead, Opportunity
from haystack import site
from haystack.indexes import *
class LeadIndex(SearchIndex):
text = CharField(document=True, use_template=True)
company = CharField(model_attr='company__name')
contact_name = MultiValueField()
contact_city = MultiValueField()
contact_state = MultiValueField()
contact_postcode = MultiValueField()
contact_email = MultiValueField()
contact_phone = MultiValueField()
product = CharField(model_attr='product__name')
campaign = CharField(model_attr='campaign__name')
def index_queryset(self):
"""Used when the entire index for model is updated."""
return Lead.objects.filter(pub_date__lte=datetime.datetime.now())
def prepare_contact_name(self, obj):
return [contact.name for contact in obj.contact_set.order_by('name')]
def prepare_contact_city(self, obj):
return [contact.city for contact in obj.contact_set.order_by('city')]
def prepare_contact_state(self, obj):
return [contact.state for contact in obj.contact_set.order_by('state')]
def prepare_contact_postcode(self, obj):
return [contact.postcode for contact in obj.contact_set.order_by('postcode')]
def prepare_contact_email(self, obj):
return [contact.email for contact in obj.contact_set.order_by('email')]
def prepare_contact_phone(self, obj):
return [contact.phone for contact in obj.contact_set.order_by('phone')]
site.register(Lead, LeadIndex)
而且我/templates/search/indexes/lead/lead_text.txt
只是
{{ object.company__name }}
我缺少什麼?
在此先感謝。