Search code examples
pythonwhoosh

Show all hits in results() object Whoosh


I'm newbie in python and whoosh so perhaps is because of that i'm having difficults to print all the hits returned after a search.

Here's my code:

from whoosh.qparser import QueryParser
with ix.searcher() as searcher:
    query = QueryParser("title", ix.schema).parse("hd")
    results = searcher.search(query)
    print results[0]
    print results
    print len(results), 'resultados'

Here's the output:

<Hit {'brand': u'Best Buy', 'title': u'best buy easy snap hd', 'superpadre': u'audio foto video', 'familia': u'videocamaras', 'detalle_short': u'Easy Snap HD es una pequena videocamara con grabacion en alta definicion ideada para poder llevarla a cualquier lugar. Su ligero peso y su visor TFT LCD de 2,7  con'}>
<Top 10 Results for Term('title', u'hd') runtime=0.000622987747192>
18 resultados

Solution

  • To print all results, you should just iterate through the object results:

    for r in results:
            print r
            print "title :", r["title"] # print the title of each result.