2010-03-07 39 views
12

我正在使用乾草堆與whoosh作爲後端的Django應用程序。飛快索引查看器

有什麼方法可以查看由whoosh生成的索引的內容(易於閱讀的格式)嗎?我想查看哪些數據已編入索引,以及如何更好地瞭解其工作原理。

回答

12

您可以從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的模板系統也許漂亮的格式化)返回文檔Django視圖:請參見更多信息嗖的一聲文檔:http://packages.python.org/Whoosh/index.html

5
from whoosh.index import open_dir 
ix = open_dir('whoosh_index') 
ix.searcher().documents() # will show all documents in the index. 
+0

這將返回一個不可下標的生成器對象。我們如何可視化結果? – 2017-04-15 20:41:48

+0

如果你想要它是可下載的,你可以嘗試在它上面調用list()。 – 2017-04-16 02:10:15