23 lines
699 B
Python
23 lines
699 B
Python
|
import os
|
||
|
|
||
|
from whoosh.fields import *
|
||
|
from whoosh.index import open_dir
|
||
|
from whoosh.qparser import QueryParser
|
||
|
|
||
|
from csvparser.csvparser import getfullpublication
|
||
|
|
||
|
SCRIPT_DIR = os.path.dirname(__file__)
|
||
|
DATA_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, "data"))
|
||
|
|
||
|
|
||
|
def search(searchinput):
|
||
|
"""search and get search result titles and return them as book ids"""
|
||
|
ix = open_dir(DATA_DIR)
|
||
|
with ix.searcher() as searcher:
|
||
|
query = QueryParser("content", ix.schema).parse(searchinput)
|
||
|
search_results = searcher.search(query)
|
||
|
searched_book_ids = []
|
||
|
for book in search_results:
|
||
|
searched_book_ids.append(book["title"])
|
||
|
return searched_book_ids
|