Commit 3c7e8bc9 authored by Alexandre Dulaunoy's avatar Alexandre Dulaunoy
Browse files

-o option added - to group search query by OR clause

parent c8faeaf0
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@

import os

from whoosh import index
from whoosh import index, qparser
from whoosh.fields import Schema, TEXT, ID
from whoosh.qparser import QueryParser

@@ -33,6 +33,7 @@ ix = index.open_dir(indexpath)

argParser = argparse.ArgumentParser(description='Full text search for cve-search')
argParser.add_argument('-q', action='append', help='query to lookup (one or more)')
argParser.add_argument('-o', action='store_true', help='OR of the query to lookup (default is AND')
argParser.add_argument('-t', action='store_true', help='output title of the match CVE(s)')
argParser.add_argument('-f', action='store_true', help='output matching CVE(s) in JSON')
argParser.add_argument('-m', type=int, default=False, help='most frequent terms in CVE description (m is top-m values)')
@@ -53,7 +54,11 @@ if args.f or args.t:

if args.q:
    with ix.searcher() as searcher:
        if not args.o:
            query = QueryParser("content", ix.schema).parse(" ".join(args.q))
        else:
            query = QueryParser("content", schema=ix.schema, group=qparser.OrGroup).parse(" ".join(args.q))

        results = searcher.search(query, limit=None)
        for x in results:
            if not args.f: