嗖嗖索引查看器

发布于 2024-08-24 22:00:46 字数 128 浏览 3 评论 0原文

我使用 haystack 和 whoosh 作为 Django 应用程序的后端。

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

I'm using haystack with whoosh as backend for a Django app.

Is there any way to view the content (in a easy to read format) of the indexes generated by whoosh? I'd like to see what data was indexed and how so I can better understand how it works.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沙沙粒小 2024-08-31 22:00:46

您可以通过 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 视图中的 whoosh 返回文档(也许可以使用 django 的模板系统进行漂亮的格式化):有关更多信息,请参阅 whoosh 文档:http://packages.python.org/Whoosh/index.html

You can do this pretty easily from python's interactive console:

>>> 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']>

You can perform search queries directly on your index and do all sorts of fun stuff. To get every document I could do this:

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

If you wanted to print it all out (for viewing or whatnot), you could do so pretty easily using a python script.

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

You could also return the documents directly from whoosh in a django view (for pretty formatting using django's template system perhaps): Refer to the whoosh documentation for more info: http://packages.python.org/Whoosh/index.html.

哭了丶谁疼 2024-08-31 22:00:46
from whoosh.index import open_dir
ix = open_dir('whoosh_index')
ix.searcher().documents()  # will show all documents in the index.
from whoosh.index import open_dir
ix = open_dir('whoosh_index')
ix.searcher().documents()  # will show all documents in the index.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文