我正在使用haystack和whoosh作为Django应用程序的后端。
有没有办法(以一种易于阅读的格式)查看由whoosh生成的索引的内容?我想看看索引的数据是什么,以及如何索引,这样我就可以更好地理解它是如何工作的。
发布于 2011-03-14 17:46:48
您可以从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的模板系统进行更好的格式化):有关更多信息,请参阅http://packages.python.org/Whoosh/index.html文档。
发布于 2012-10-23 11:00:11
from whoosh.index import open_dir
ix = open_dir('whoosh_index')
ix.searcher().documents() # will show all documents in the index.https://stackoverflow.com/questions/2395675
复制相似问题