Django-Haystack/Whoosh - 重建索引错误
我在使用Python 2.5和Django 1.2.1,最新的haystack和whoosh。
这是我第一次接触Django-Haystack。我按照Haystack的“入门指南”在操作,一切看起来都很顺利,直到我开始构建索引的时候。
我运行“manage.py rebuild_index”时,出现了这个错误:
Traceback (most recent call last):
File "/Users/steenb/Documents/Aptana Studio Workspace/bucksac/buckshr/manage.py", line 11, in <module>
execute_manager(settings)
File "/Library/Python/2.5/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Python/2.5/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.5/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.5/site-packages/django/core/management/base.py", line 218, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.5/site-packages/haystack/management/commands/rebuild_index.py", line 13, in handle
call_command('clear_index', **options)
File "/Library/Python/2.5/site-packages/django/core/management/__init__.py", line 166, in call_command
return klass.execute(*args, **defaults)
File "/Library/Python/2.5/site-packages/django/core/management/base.py", line 218, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.5/site-packages/haystack/management/commands/clear_index.py", line 38, in handle
sb.clear()
File "/Library/Python/2.5/site-packages/haystack/backends/whoosh_backend.py", line 212, in clear
self.index.commit()
AttributeError: 'FileIndex' object has no attribute 'commit'
我都不知道从哪里开始解决这个问题……有没有人遇到过类似的情况?
有没有什么解决办法?
更新:我也试着用Python 2.6运行,结果还是出现了同样的错误。是不是我漏掉了什么Whoosh的配置?
更新:在使用philippbosch的建议后,之前的错误不再出现了,但现在我遇到了这个:
Traceback (most recent call last):
File "/Users/steenb/Documents/Aptana Studio Workspace/bucksac/buckshr/manage.py", line 11, in <module>
execute_manager(settings)
File "/Library/Python/2.5/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Python/2.5/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.5/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.5/site-packages/django/core/management/base.py", line 218, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.5/site-packages/haystack/management/commands/update_index.py", line 69, in handle
return super(Command, self).handle(*apps, **options)
File "/Library/Python/2.5/site-packages/django/core/management/base.py", line 282, in handle
app_output = self.handle_app(app, **options)
File "/Library/Python/2.5/site-packages/haystack/management/commands/update_index.py", line 123, in handle_app
index.backend.update(index, small_cache_qs[start:end])
File "/Library/Python/2.5/site-packages/haystack/backends/whoosh_backend.py", line 163, in update
writer = AsyncWriter(self.index.writer, postlimit=self.post_limit)
TypeError: __init__() got an unexpected keyword argument 'postlimit'
我在想我是不是用的Whoosh版本不兼容……我下载的是最新的1.0.0b2版本…… http://pypi.python.org/pypi/Whoosh/
更新:结果发现是版本问题。目前,Haystack是和whoosh 0.3.18版本绑定的。
3 个回答
0
如果你在尝试从索引中删除一个条目时找到了这个问题,你可能需要使用一个 IndexWriter
来删除这个条目,而不是使用 FileIndex
对象;比如:
不要这样做:
ix = open_dir('index')
ix.delete_by_term('path', u'/a/b/c')
ix.commit()
这样会出现上面讨论的错误,你可以通过运行以下代码来删除一个文件:
ix = open_dir('index')
writer = ix.writer()
writer.delete_by_term('path', u'/a/b/c')
writer.commit()
1
在我这边,安装了 Whoosh 0.3.18 后,问题就解决了。
6
我刚才也遇到同样的问题。你试过用 »update_index« 吗,而不是 »rebuild_index«?对我来说,这个方法好像有效 …