Python 在results()对象中显示所有点击
我是python和whoosh方面的新手,所以可能正因为如此,我很难打印搜索后返回的所有点击 这是我的密码:Python 在results()对象中显示所有点击,python,whoosh,Python,Whoosh,我是python和whoosh方面的新手,所以可能正因为如此,我很难打印搜索后返回的所有点击 这是我的密码: 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
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'
以下是输出:
<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
18结果
看起来你已经走上了正确的轨道。但实际上可能只有一个结果
根据该报告,呼吁:
len(结果)
按原样提供搜索匹配的总数
因此,如果结果在这里显示“1个resultados”,那么这可能就是索引的全部内容 要打印所有结果,只需遍历对象
results
:
for r in results:
print r
print "title :", r["title"] # print the title of each result.
公认的答案具有误导性;它将提供搜索中受“限制”参数限制的点击数 要修改该限制,请使用:
results = searcher.search(query, limit=None)
使用搜索。这是正确的,但当结果超过1时也会发生这种情况。