繁体   English   中英

在Python上使用Whoosh入门

[英]Getting started with Whoosh on Python

我是python和Whoosh的完全新手。

我需要创建一个搜索引擎,使我可以在XML文件中进行搜索。 为此,我从命令提示符下下载了Whoosh

setup.py build 

setup.py install  

然后,我从http://pythonhosted.org/Whoosh/quickstart.html提取了示例代码

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()

from whoosh.qparser import QueryParser
with ix.searcher() as searcher:
query = QueryParser("content", ix.schema).parse("first")
results = searcher.search(query)
results[0]

而且我收到了一个Unresolved import error:create_inQueryParser也是如此。

我不确定是否必须添加一些路径变量。 关于Whoosh入门的文档不足,相反,示例代码越来越多。

提前致谢!

我强烈建议您使用诸如easy_install或PIP之类的模块安装程序,而不是手动安装模块,因为这样可以避免许多问题(例如,在使用pip安装whoosh之后,导入对我来说很好)。

您可以在官方网站http://www.pip-installer.org/zh-CN/latest/installing.html上学习如何安装pip,并在安装完成后进行操作-只需简单地安装whoosh

pip install whoosh

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM