【问题标题】:spell check with haystack用 haystack 进行拼写检查
【发布时间】:2013-05-22 10:24:41
【问题描述】:

我在拼写检查中没有得到任何结果

首先我在 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 替换它重建索引。查看 solrconfig.xml 以进行适当的更改。 通过django shell测试

>>> from haystack.query import SearchQuerySet
>>> sqs = SearchQuerySet().auto_query('spider')
>>> suggestion = sqs.spelling_suggestion()
>>> print suggestion
>>> None

None,谁能帮帮我?

【问题讨论】:

    标签: django solr spell-checking django-haystack


    【解决方案1】:

    您应该使用以下命令重建索引:

    python manage.py rebuild_index

    来自the docs

    要工作,您必须在连接的设置字典中将 INCLUDE_SPELLING 设置为 True,然后您必须重建索引。否则,将返回 None。

    【讨论】:

      【解决方案2】:

      为了使用 SearchQuerySet 进行拼写检查,您需要将拼写检查组件绑定到标准查询处理程序。

      这是通过将其添加到 solrconfig.xml 文件中的默认 requestHandler 来完成的:

       <arr name="last-components">
           <str>spellcheck</str>
           ...         
       </arr>
      

      有关更多信息,请参阅此主题:Solr spelling suggestions returns 'None'

      【讨论】:

        猜你喜欢
        • 2016-01-22
        • 1970-01-01
        • 2012-08-20
        • 2014-11-26
        • 2011-11-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-27
        相关资源
        最近更新 更多