【问题标题】:Spelling Suggestions showing 'None' haystack显示“无”干草堆的拼写建议
【发布时间】:2013-06-12 08:08:41
【问题描述】:

为拼写建议获取“无”。

settings.py 包含“INCLUDE_SPELLING”:是的

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.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" />

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

【问题讨论】:

  • 您使用的是哪个 haystack 版本?

标签: django solr spell-checking django-haystack


【解决方案1】:

嗯,我可以使用演示应用程序。

这是我的演示应用程序,包括 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 给出关于version 字段的错误,则将其添加到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 更改搜索查询

【讨论】:

  • 我想查看您使用拼写建议的搜索模板。
  • 我正在这样展示它们{{ 建议 }}
  • 实际上我使用的是默认搜索表单..n 我没有任何视图..我需要编写自己的视图吗?
  • 理想情况下,默认搜索表单也应该可以工作,当您使用默认搜索表单时,请检查它发送给 solr 的查询。您可以在 solr 服务器终端窗口中查看它
  • 不,尝试了一切,但仍然显示“无”..无论如何,非常感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 2014-06-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-15
  • 2014-07-18
相关资源
最近更新 更多