首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Whoosh中保存索引

在Whoosh中保存索引
EN

Stack Overflow用户
提问于 2015-05-31 14:40:01
回答 1查看 1.2K关注 0票数 0

我正在寻找一个建议,或者最好是一个例子,来存储或保存呼呼的索引。我在Windows 7专业版上使用Python 2.7。如果有人能帮忙的话。

EN

回答 1

Stack Overflow用户

发布于 2015-05-31 17:53:15

Whoosh有很好的文档记录,您可以在Official documentation中找到大多数内容。以下是快速入门中的Indexer-Searcher示例:

代码语言:javascript
复制
# Indexer
>>> from whoosh.index import create_in
>>> from whoosh.fields import *
>>> schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT)
>>> ix = create_in("indexdir", schema)
>>> writer = ix.writer()
>>> writer.add_document(title=u"First document", path=u"/a",
...                     content=u"This is the first document we've added!")
>>> writer.add_document(title=u"Second document", path=u"/b",
...                     content=u"The second one is even more interesting!")
>>> writer.commit()

# Searcher 
>>> from whoosh.qparser import QueryParser
>>> with ix.searcher() as searcher:
...     query = QueryParser("content", ix.schema).parse("first")
...     results = searcher.search(query)
...     results[0]
...
{"title": u"First document", "path": u"/a"}

该示例在details there中进行了解释。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30554618

复制
相关文章

相似问题

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