如何解决当我打开它以添加新文档时,Whoosh 索引文件被覆盖
我有 Whoosh 的问题。我想在不同的时刻创建一个索引,因为提取数据的查询很繁重。我解决了几乎所有的问题,但是我无法克服每次重新打开索引以添加新文档时,文件都会被清理而不是简单地添加新文档的问题。我尝试使用 update_document
代替 add_document
,使用 FileStorage.open_index
代替 index.open_dir
,但没有任何改变:我的索引文件总是比预期的要小得多。
if is_new_index_file:
if os.path.isdir(<dirname>):
rmtree(<dirname>)
os.mkdir(<dirname>)
else:
os.mkdir(<dirname>)
schema = TranslationSchema()
index.create_in(<dirname>,<schema>,indexname=<indexname>)
ix = index.open_dir(<dirname>,indexname=<indexname>,schema=<schema>)
else:
#open an existing index object
# ix = index.open_dir(<dirname>,indexname=<indexname>)
# open file storage
ix = FileStorage(<dirname>)
ix.open_index(indexname = <indexname>)
...
list-of-fields = <query-to-the-database-to-extract-fields>
...
writer = ix.writer()
#writer.add_document(<list-of-fields>)
writer.update_document(<list-of-fields>)
writer.commit(merge=False,optimize=True)
ix.close()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。