2013-03-07 47 views
0

我对django haystack完全陌生,而且我正面临着麻烦。django干草堆面临错误搜索时遇到的麻烦 - undefined field django_ct

当我搜索我得到错误

Failed to query Solr using '*:*': [Reason: Error 400 undefined field django_ct] 

当我需要重新建立索引我得到这个错误

WARNING: This will irreparably remove EVERYTHING from your search index in connection 'default'. Your choices after this are to restore from backups or rebuild via the `rebuild_index` command. 
Are you sure you wish to continue? [y/N] y 
Removing all documents from your index because you said so. 
All documents removed. 
ERROR:root:Error updating votingapp using default 
Traceback (most recent call last): 
... 
... 
index_qs = self.index_queryset(using=using) 
TypeError: index_queryset() got an unexpected keyword argument 'using' 

我已经建立了一个简单的指数类

class QuestionsIndex(indexes.SearchIndex, indexes.Indexable): 
    text = indexes.CharField(document=True, use_template=True) 
    qs = indexes.CharField(model_attr='question') 

    def get_model(self): 
     return Questions 

    def index_queryset(self): 
     return self.get_model().objects.all() 

中添加的代码settings.py

HAYSTACK_CONNECTIONS = { 
    'default': { 
     'ENGINE': 'haystack.backends.solr_backend.SolrEngine', 
     'URL': 'http://127.0.0.1:8983/solr' 
     # ...or for multicore... 
     # 'URL': 'http://127.0.0.1:8983/solr/mysite', 
    }, 
} 

添加URL

url(r'^search/', include('haystack.urls')), 

视图代码

def home(request): 
    if request.method == "POST": 
     print SearchQuerySet().all() 
    return render_to_response('search.html',{}) 

请告知我在哪里做错了

+2

你还没有添加index_queryset()'的'using = None' keyworded参数。如果你想要那个关键字,它应该是'index_queryset(self,using = None)'。 – 2013-03-07 10:22:34

+0

嘿谢谢,现在我得到这个错误,同时重建 - >无法将文件添加到Solr:[原因:错误400错误:[doc = votingapp.questions.1]未知字段'django_ct']。你能告诉我理解干草堆工作的很好的参考吗 – Sandy 2013-03-07 10:26:27

+0

你的'schema.xml'是否有'django_ct'字段?好的文档是实际的文档 - > https://django-haystack.readthedocs.org/en/v1.2.7/tutorial.html – 2013-03-07 10:27:19

回答