This is the varia library website work in progress.
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.
 
 
 
 
 

22 lines
699 B

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