django - 显示 'None' haystack 的拼写建议

标签 django solr spell-checking django-haystack

拼写建议为“无”。

settings.py 包含“INCLUDE_SPELLING”:True

搜索索引.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.CharField()

    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

多次重建索引。

solrconfig.xml

<searchComponent name="spellcheck" class="solr.SpellCheckComponent">

    <str name="queryAnalyzerFieldType">textSpell</str>

    <lst name="spellchecker">
      <str name="name">default</str>
      <str name="field">suggestions</str>
      <str name="spellcheckIndexDir">./spellchecker1</str>
      <str name="buildOnCommit">true</str>

    </lst>

<requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">
    <lst name="defaults">
      <str name="df">text</str>
      <str name="spellcheck.onlyMorePopular">false</str>
      <str name="spellcheck.extendedResults">false</str>
      <str name="spellcheck.count">1</str>
    </lst>
    <arr name="last-components">
      <str>spellcheck</str>
    </arr>
  </requestHandler>

schema.xml 包含建议字段

<field name="suggestions" type="text_en" indexed="true" stored="true" multiValued="true" termVectors="true" termPositions="true" termOffsets="true" />

谁能告诉我为什么它显示“无”吗?

最佳答案

嗯,我已经在演示应用程序中使用它了。

这是我的演示应用程序,包括 solr conf 文件。

https://dl.dropboxusercontent.com/u/43002805/mysite.zip

这是我正在使用的。

Django 1.5.1

干草堆2.0

Solr 4.3.0

首先通过管理界面添加示例数据。 然后使用构建 solr 架构

python manage.py build_solr_schema > path/to/solr/conf/dir/schema.xml

启动 Solr java 服务器

python manage.py rebuild_index

如果rebuild_index给出有关版本字段的错误,则将其添加到schema.xml字段标记

重建索引后,您必须点击此 URL 一次才能构建拼写建议字典

http://localhost:8983/solr/select?q=tes&spellcheck=true&spellcheck.collate=true&spellcheck.build=true

python manage.py runserver

使用 localhost:8000/jobs 尝试一下

根据您的示例数据更改views.py中的搜索查询

关于django - 显示 'None' haystack 的拼写建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17060612/

相关文章:

java - solr 和 lucene 的区别

linux - bash - 删除不当的词

python - 在 Django 模板中渲染空白 ImageFields

Elastic Beanstalk 上的 SOLR

django - 我无法在我的 Mac 上启动 rabbitmq

solr - 我如何使用 lucene 查询找到空的 Solr 文档字段

jquery - ASP.NET MVC 有拼写检查器吗?

.net - 带有 SpellCheck.IsEnabled ="True"的 WPF 文本框 - 没有发生拼写检查?

使用比较运算符的 Python 条件变量赋值

主页上的 django allauth 登录和注册表单