Whoosh索引查看器 [英] Whoosh index viewer

查看:141
本文介绍了Whoosh索引查看器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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.

推荐答案

您可以执行此操作从python的交互式控制台非常容易:

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

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

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

您也可以直接从飞快移动返回文档django视图(也许可以使用django的模板系统进行漂亮的格式化):有关更多信息,请参阅whoosh文档: http ://packages.python.org/Whoosh/index.html

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.

这篇关于Whoosh索引查看器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆