From 5bfca0f3d95966f3c48d80b9b0fee2b0ac90024b Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Wed, 4 Feb 2015 20:58:27 +0100 Subject: [PATCH] Sample script to search the full-text index --- bin/x509/search.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 bin/x509/search.py diff --git a/bin/x509/search.py b/bin/x509/search.py new file mode 100644 index 0000000..a54ac76 --- /dev/null +++ b/bin/x509/search.py @@ -0,0 +1,21 @@ +import argparse +from whoosh import index +from whoosh.fields import * +from whoosh.qparser import QueryParser + + +argParser = argparse.ArgumentParser(description='Full text search') +argParser.add_argument('-q', action='append', help='query to lookup (one or more)') +args = argParser.parse_args() + +indexpath = "/tmp/findex" +schema = Schema(path=ID(stored=True, unique=True), content=TEXT) + +ix = index.open_dir(indexpath) + +if args.q: + 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['path']