1

在我中断了 whoosh 提交过程后出现了这个奇怪的错误。当我现在尝试提交时,我得到了

  File "/usr/local/lib/python2.7/dist-packages/whoosh/filedb/filewriting.py", line 179, in     _check_state
    raise IndexingError("This writer is closed")
whoosh.writing.IndexingError: This writer is closed

我试图重新安装lib,更改索引目录,但它不起作用。那么我该如何修复嗖嗖声?

4

1 回答 1

1

我认为没有必要“修复嗖嗖”(或索引)。

可能只是您的代码打开了一个编写器,可能使用它,关闭它,然后再次尝试使用关闭的编写器。

总是这样做:

with myindex.writer() as w:
    w.add_document(title=u"First document", content=u"Hello there.")
    w.add_document(title=u"Second document", content=u"This is easy!")

如果您以后需要添加更多文档(在这个“with”块之外),以同样的方式打开一个新的作家......

注意:编写器 w 在离开 with 块时会自动关闭,这就是所谓的上下文管理器的工作方式。

于 2013-02-24T12:52:53.933 回答