python whoosh IndexingError when interrupted

回眸只為那壹抹淺笑 提交于 2019-12-10 11:36:38

问题


This strange error appears after i had interrupted whoosh commit process. When i am trying to commit now i'm getting

  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

I've tried to reinstall lib, change the index directory but it doesn't work. So how could i repair whoosh?


回答1:


I think there is no need to "repair whoosh" (or the index).

It might be simply your code that opens a writer, uses it maybe, closes it and then tries to use the closed writer again.

Just always do it like that:

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!")

And if you need to add more documents later (outside this "with"-block), open a new writer the same way...

Note: the writer w gets automatically closed when leaving the with-block, that's how a so-called context manager works.



来源:https://stackoverflow.com/questions/14447641/python-whoosh-indexingerror-when-interrupted

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!