mirror of
https://github.com/adulau/crl-monitor.git
synced 2024-11-22 01:57:05 +00:00
Sample script to search the full-text index
This commit is contained in:
parent
e8e27f68b2
commit
5bfca0f3d9
1 changed files with 21 additions and 0 deletions
21
bin/x509/search.py
Normal file
21
bin/x509/search.py
Normal file
|
@ -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']
|
Loading…
Reference in a new issue