Spaces:
Sleeping
Sleeping
File size: 592 Bytes
efeacc7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
from whoosh import index
from whoosh.qparser import MultifieldParser
from whoosh import qparser
acronym_regex = r"([A-Z][\w,’‘']+(?:(?:\s|&|and|or|the|of|to|in|on|at|for|an|-)+[A-Z][\w,’‘']+){1,})\s\(([A-Za-z\s]+)\)"
def search(query,index_dir):
ix = index.open_dir(index_dir)
mparser = MultifieldParser(["title", "content","date","acronyms"], schema=ix.schema,group=qparser.OrGroup)
q = mparser.parse(query)
s = ix.searcher()
print(q)
results = s.search(q, limit=10)
for r in results:
print(r['title'],r['file_name'])
return(list(results))
|