Whoosh index viewer

后端 未结 2 534
梦如初夏
梦如初夏 2021-02-02 00:16

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 lik

2条回答
  •  忘掉有多难
    2021-02-02 00:27

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

    >>> from whoosh.index import open_dir
    >>> ix = open_dir('whoosh_index')
    >>> ix.schema
    <<< 
    

    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.

提交回复
热议问题