我在拼写检查中没有
首先我在 settings.py 中进行了更改
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
'URL': 'http://127.0.0.1:8983/solr',
'INCLUDE_SPELLING': True,
},
}
在 search_indexes.py 中进行了更改
class JobIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
post_type = indexes.CharField(model_attr='post_type',faceted=True)
job_location = indexes.CharField(model_attr='job_location',faceted=True)
job_type = indexes.CharField(model_attr='job_type',faceted=True)
company_name = indexes.CharField(model_attr='company_name',faceted=True)
job_title = indexes.CharField(model_attr='job_title', faceted=True)
start_date = indexes.DateField(model_attr='start_date', faceted=True)
end_date = indexes.DateField(model_attr='end_date', faceted=True)
job_description = indexes.CharField(model_attr='job_description', faceted=True)
country = indexes.CharField(model_attr='country', faceted=True)
suggestions = indexes.FacetCharField()
def prepare(self, obj):
prepared_data = super(JobIndex, self).prepare(obj)
prepared_data['suggestions'] = prepared_data['text']
return prepared_data
def get_model(self):
return jobpost
def index_queryset(self,**kwargs):
return self.get_model().objects.all()
然后让 solr_schema 替换它重建 index..looked solrconfig.xml 以进行适当的更改。通过 django shell 测试
>>> from haystack.query import SearchQuerySet
>>> sqs = SearchQuerySet().auto_query('spider')
>>> suggestion = sqs.spelling_suggestion()
>>> print suggestion
>>> None
明白None
了,谁能帮帮我?