与python whoosh IndexingError when interrupted不同,我没有中断任何提交,但是在创建新索引时会发生IndexingError:
import uuid
import os
from whoosh.index import create_in
from whoosh.fields import *
from whoosh.qparser import QueryParser
schema = Schema(hashID=TEXT(stored=True))
indexdir = 'foobar'
if not os.path.exists(indexdir):
os.mkdir(indexdir)
ix = create_in(indexdir, schema)
with ix.writer() as writer:
writer.add_document(hashID=str(uuid.uuid4()))
writer.commit()错误:
---------------------------------------------------------------------------
IndexingError Traceback (most recent call last)
<ipython-input-1-85a42bebdce8> in <module>()
15 with ix.writer() as writer:
16 writer.add_document(hashID=str(uuid.uuid4()))
---> 17 writer.commit()
/usr/local/lib/python3.5/site-packages/whoosh/writing.py in __exit__(self, exc_type, exc_val, exc_tb)
208 self.cancel()
209 else:
--> 210 self.commit()
211
212 def group(self):
/usr/local/lib/python3.5/site-packages/whoosh/writing.py in commit(self, mergetype, optimize, merge)
918 """
919
--> 920 self._check_state()
921 # Merge old segments if necessary
922 finalsegments = self._merge_segments(mergetype, optimize, merge)
/usr/local/lib/python3.5/site-packages/whoosh/writing.py in _check_state(self)
553 def _check_state(self):
554 if self.is_closed:
--> 555 raise IndexingError("This writer is closed")
556
557 def _setup_doc_offsets(self):
IndexingError: This writer is closed作者应该在上下文范围内,所以我不知道为什么关闭它,尽管它是新创建的。如何解析新索引上的IndexingError?
发布于 2017-12-22 19:32:44
writer.commit()保存更改并关闭写入器。
然后,在语句的末尾,with ix.writer() as writer:试图关闭已经关闭且不存在的作者。
因此,您的with语句等效于:
try:
writer = ix.writer()
writer.add_document(hashID=str(uuid.uuid4()))
writer.commit()
finally:
writer.commit()作为一种解决方案,无论是在with语句中省略with,还是在每次提交时删除with语句并重新创建writer。
https://stackoverflow.com/questions/43773095
复制相似问题