Django 2.0 haystack whoosh 更新索引,重建索引抛出错误

Posted

技术标签:

【中文标题】Django 2.0 haystack whoosh 更新索引,重建索引抛出错误【英文标题】:Django 2.0 haystack whoosh update index, rebuild index throw error 【发布时间】:2018-07-06 16:29:23 【问题描述】:

我使用 django 2.0 和 haystack+whoosh 作为搜索。我按照文档中的说明进行了配置。发生的问题是当我运行./manage.py rebuild_index 时显示此错误:

Traceback (most recent call last):
  File "./manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/django/core/management/__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/django/core/management/base.py", line 335, in execute
    output = self.handle(*args, **options)
  File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/management/commands/rebuild_index.py", line 36, in handle
    call_command('clear_index', **options)
  File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/django/core/management/__init__.py", line 133, in call_command
    ', '.join(sorted(valid_options)),
TypeError: Unknown option(s) for clear_index command: batchsize, workers. Valid options are: commit, help, interactive, no_color, nocommit, noinput, pythonpath, settings, skip_checks, stderr, stdout, traceback, using, verbosity, version.

之后我尝试了update_index,它显示了这个错误:

File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/management/commands/update_index.py", line 214, in handle self.update_backend(label, using)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/management/commands/update_index.py", line 257, in update_backend
commit=self.commit, max_retries=self.max_retries)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/management/commands/update_index.py", line 84, in do_update
backend.update(index, current_qs, commit=commit)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/backends/whoosh_backend.py", line 185, in update
doc = index.full_prepare(obj)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/indexes.py", line 208, in full_prepare
self.prepared_data = self.prepare(obj)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/indexes.py", line 199, in prepare
self.prepared_data[field.index_fieldname] = field.prepare(obj)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/fields.py", line 205, in prepare
return self.convert(super(CharField, self).prepare(obj))
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/fields.py", line 88, in prepare
values = self.resolve_attributes_lookup(current_objects, attrs)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/fields.py", line 131, in resolve_attributes_lookup
values.append(current_object())
TypeError: __call__() missing 1 required keyword-only argument: 'manager'

那么有人遇到过这个错误吗?它是否与 django 2.0 相关,因为我管理它与 django 1.11 配合得很好。

【问题讨论】:

这对我也不起作用。也许有人会回答这个问题:***.com/questions/48684419/… 【参考方案1】:

您安装的 Haystack 版本不支持 Django 2.0。在 2018 年 3 月发布的 Haystack 2.8 中添加了对 Django 2.0 的支持。

【讨论】:

以上是关于Django 2.0 haystack whoosh 更新索引,重建索引抛出错误的主要内容,如果未能解决你的问题,请参考以下文章

Django-cms haystack 搜索 - 占位符内容

什么是 django-haystack 的好示例 solrconfig.xml?

Django - Haystack 查询序列化

django使用全文搜索引擎haystack+jieba分词

Django之使用haystack+whoosh实现搜索功能

Django:关于使用 Solr 和 Haystack 的问题