我正在使用代码,并得到了错误消息。
--这里的作者是封闭的
我用的是哇和蟒蛇。我从一个json文件中获取数据,然后迭代一个循环来创建搜索引擎索引。
from whoosh.fields import Schema,TEXT,ID
from whoosh import index
from whoosh.qparser import QueryParser
import os.path
import json
if not os.path.exists("indexdir"):
os.mkdir("indexdir")
schema = Schema(title=TEXT(stored=True), content=TEXT(stored=True))
ix = index.create_in("indexdir", schema)
doc_json=json.load(open("review.json",'r'))
for doc in doc_json:
with ix.writer() as w:
for key,value in doc.get('properties').items():
w.add_document(title=str(key), content=str(value[0].get('value')))
w.commit()发布于 2020-02-20 08:40:55
w.commit()关闭编写器,这样就可以这样做:
with ix.writer() as w:
for doc in doc_json:
for key,value in doc.get('properties').items():
w.add_document(title=str(key), content=str(value[0].get('value')))
w.commit()https://stackoverflow.com/questions/60307994
复制相似问题