4

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
Assem
  • 11,574
  • 5
  • 59
  • 97
Claudia Guirao
  • 335
  • 1
  • 3
  • 10

3 Answers3

4

The accepted answer is misleading; it will give you the number of hits limited by "limit" parameter in the search.

To modify that limit, use:

results = searcher.search(query, limit=None)

to search with.

petermolnar
  • 1,626
  • 14
  • 23
2

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.
Assem
  • 11,574
  • 5
  • 59
  • 97
0

It looks like you are already on the right track. But there might actually only be one result.

According to the whoosh docs, calling:

len(results)

as you are, gives you the total number of search matches.

So if the result is showing "1 resultados" here, that's likely all that's indexed.

otherchirps
  • 1,836
  • 1
  • 19
  • 26