from whoosh import index from whoosh.qparser import MultifieldParser import bottle from bottle import route, run, request @route('/search') def search(): term = request.query.get("q") if not term: return { 'error': 'No search term specified' } idx = index.open_dir("indexdir") parser = MultifieldParser( ["track_name", "artist", "album"], schema=idx.schema) with idx.searcher() as searcher: results = searcher.search(parser.parse(term)) return { 'results': [dict(result) for result in results] } bottle.debug(True) app = bottle.default_app() #if __name__ == "__main__": run(host='localhost', port=8080)