在呼啸声中保存索引

2024-09-27 00:17:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在寻找一个建议,或者最好是一个例子,来存储或保存Whoosh的索引。我在Windows7Professional上使用Python2.7。 如果有人愿意帮忙的话。在


Tags: 建议例子whooshwindows7professional
1条回答
网友
1楼 · 发布于 2024-09-27 00:17:05

Whoosh有很好的文档记录,您可以在Official documentation中找到大部分内容。以下是快速入门中的索引器搜索器示例:

# 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"}

这个例子在there中有详细的解释。

相关问题 更多 >

    热门问题