gpt4 book ai didi

python - Whoosh 索引查看器

转载 作者:太空狗 更新时间:2023-10-29 17:15:08 30 4
gpt4 key购买 nike

我正在使用带有 whoosh 的 haystack 作为 Django 应用程序的后端。

有什么方法可以查看whoosh生成的索引的内容(以易于阅读的格式)?我想看看索引了哪些数据以及如何索引,以便更好地理解它的工作原理。

最佳答案

您可以从 python 的交互式控制台很容易地做到这一点:

>>> from whoosh.index import open_dir
>>> ix = open_dir('whoosh_index')
>>> ix.schema
<<< <Schema: ['author', 'author_exact', 'content', 'django_ct', 'django_id', 'id', 'lexer', 'lexer_exact', 'published', 'published_exact']>

您可以直接在索引上执行搜索查询并执行各种有趣的操作。要获取每份文件,我可以这样做:

>>> from whoosh.query import Every
>>> results = ix.searcher().search(Every('content'))

如果您想将其全部打印出来(用于查看或其他目的),您可以使用 python 脚本轻松完成。

for result in results:
print "Rank: %s Id: %s Author: %s" % (result.rank, result['id'], result['author'])
print "Content:"
print result['content']

您还可以在 django View 中直接从 whoosh 返回文档(也许使用 django 的模板系统进行漂亮的格式化):请参阅 whoosh 文档以获取更多信息:http://packages.python.org/Whoosh/index.html .

关于python - Whoosh 索引查看器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2395675/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com