首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Whoosh :作者关闭了

Whoosh :作者关闭了
EN

Stack Overflow用户
提问于 2020-02-19 19:39:12
回答 1查看 165关注 0票数 0

我正在使用代码,并得到了错误消息。

--这里的作者是封闭的

我用的是哇和蟒蛇。我从一个json文件中获取数据,然后迭代一个循环来创建搜索引擎索引。

代码语言:javascript
复制
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()
EN

回答 1

Stack Overflow用户

发布于 2020-02-20 08:40:55

w.commit()关闭编写器,这样就可以这样做:

代码语言:javascript
复制
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()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60307994

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档