0
下面是例子中,我嘗試爲大集合與最終嗖Python的嗖的BufferedWriter不提交到磁盤
schema = Schema(name=TEXT(stored=True), m=ID(stored=True), content=KEYWORD(stored=True))
ix = create_in("indexdir", schema)
from whoosh.writing import BufferedWriter
from multiprocessing import Pool
jobs = []
writer = BufferedWriter(ix, period=15, limit=512, writerargs = {"limitmb": 512})
for item in cursor:
if len(jobs) < 1024:
jobs.append(item)
else:
p = Pool(8)
p.map(create_barrel, jobs)
p.close()
p.join()
jobs = []
writer.commit()
create_barrel功能執行以下操作:
writer.add_document(name = name, m = item['_id'], content = " ".join(some_processed_data))
還在運行幾個小時後,索引是空的,並且indexdir中唯一的文件是鎖定文件_MAIN_0.toc
上面的代碼適用於切換無AsyncWriter但s ome的原因AsyncWriter錯過了大約90%的提交和標準作家對我來說太慢了。
爲什麼BufferedWriter未能提交?
我只試過2.4.1。它由pip安裝。我應該嘗試哪個其他分支?另外,你對代碼中的其他問題還是正確的,但我擁有3.5百萬個項目,並不在意它們中的一些是否會丟失。 – Moonwalker 2013-04-12 10:32:30