From fd6e1a84367b128537719c52371c3fc7457df3ac Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Tue, 12 Aug 2014 13:26:56 +0200 Subject: [PATCH] -f option added: dump full document for each match --- bin/tests/indexer_lookup.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/bin/tests/indexer_lookup.py b/bin/tests/indexer_lookup.py index 305ae236..110d6086 100644 --- a/bin/tests/indexer_lookup.py +++ b/bin/tests/indexer_lookup.py @@ -13,6 +13,13 @@ import ConfigParser import argparse import sys +import gzip + +def readdoc(path=None): + if path is None: + return False + f = gzip.open (path, 'r') + return f.read() configfile = '../packages/config.cfg' cfg = ConfigParser.ConfigParser() @@ -27,6 +34,8 @@ argParser.add_argument('-q', action='append', help='query to lookup (one or more argParser.add_argument('-n', action='store_true', default=False, help='return numbers of indexed documents') argParser.add_argument('-t', action='store_true', default=False, help='dump top 500 terms') argParser.add_argument('-l', action='store_true', default=False, help='dump all terms encountered in indexed documents') +argParser.add_argument('-f', action='store_true', default=False, help='dump each matching document') + args = argParser.parse_args() from whoosh import index @@ -61,5 +70,8 @@ with ix.searcher() as searcher: query = QueryParser("content", ix.schema).parse(" ".join(args.q)) results = searcher.search(query, limit=None) for x in results: - print (x) - + if args.f: + print (readdoc(path=x.items()[0][1])) + else: + print (x.items()[0][1]) + print