问题描述
我有 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 (将#修改为@)