You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
691 B
21 lines
691 B
import os
|
|
|
|
from application.csvparser import CsvParser
|
|
from whoosh.fields import *
|
|
from whoosh.index import open_dir
|
|
from whoosh.qparser import QueryParser
|
|
|
|
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
|
|
|