Improve printing of search results in script
This commit is contained in:
parent
3bcb7f42c1
commit
74107667b4
1 changed files with 12 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
|||
import logging
|
||||
import sys
|
||||
from itertools import islice
|
||||
|
||||
from mwmbl.indexer.paths import INDEX_PATH
|
||||
from mwmbl.tinysearchengine.completer import Completer
|
||||
|
@ -9,14 +10,22 @@ from mwmbl.tinysearchengine.rank import HeuristicRanker
|
|||
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
|
||||
|
||||
|
||||
def clean(sequence):
|
||||
return ''.join(x['value'] for x in sequence)
|
||||
|
||||
|
||||
def run():
|
||||
with TinyIndex(Document, INDEX_PATH) as tiny_index:
|
||||
completer = Completer()
|
||||
ranker = HeuristicRanker(tiny_index, completer)
|
||||
items = ranker.search('jasper fforde')
|
||||
items = ranker.search('google')
|
||||
print()
|
||||
if items:
|
||||
for item in items:
|
||||
print("Items", item)
|
||||
for i, item in enumerate(islice(items, 10)):
|
||||
print(f"{i + 1}. {item['url']}")
|
||||
print(clean(item['title']))
|
||||
print(clean(item['extract']))
|
||||
print()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Add table
Reference in a new issue