我正在尝试在' first_name'上实施自动填充功能。 '用户'的字段模型使用Django-Haystack-Solr。但我正面对这个"未知领域"错误。
search_indexes.py:
from haystack import indexes
from django.contrib.auth.models import User
class UserIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
firstname = indexes.EdgeNgramField(model_attr='first_name')
def get_model(self):
return User
def index_queryset(self, using=None):
return self.get_model().objects.all()
views.py
results = SearchQuerySet().autocomplete(firstname=request.POST.get("search_text",''))
我执行了以下操作:
错误:
Indexing 5 users
/usr/local/lib/python2.7/dist-packages/haystack/fields.py:137: RemovedInDjango110Warning: render() must be called with a dict, not a Context.
return t.render(Context({'object': obj}))
Failed to add documents to Solr: Solr responded with an error (HTTP 400): [Reason: ERROR: [doc=auth.user.23] unknown field 'firstname']
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/haystack/backends/solr_backend.py", line 72, in update
self.conn.add(docs, commit=commit, boost=index.get_field_weights())
File "/usr/local/lib/python2.7/dist-packages/pysolr.py", line 860, in add
return self._update(m, commit=commit, softCommit=softCommit, waitFlush=waitFlush, waitSearcher=waitSearcher)
File "/usr/local/lib/python2.7/dist-packages/pysolr.py", line 462, in _update
return self._send_request('post', path, message, {'Content-type': 'text/xml; charset=utf-8'})
File "/usr/local/lib/python2.7/dist-packages/pysolr.py", line 394, in _send_request
raise SolrError(error_message % (resp.status_code, solr_message))
SolrError: Solr responded with an error (HTTP 400): [Reason: ERROR: [doc=auth.user.23] unknown field 'firstname']
此外,如果有人可以指出我正确的方向,如何为多个字段实现自动完成。就像在这种情况下的' first_name',' last_name'和'电子邮件',我该怎么做?
解决方案 - 重新启动Solr
Stop Solr: ./solr-4.10.4/bin/solr stop -all
Start Solr: ./solr-4.10.4/bin/solr start -p 8983