summaryrefslogtreecommitdiff
path: root/src/index_service.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/index_service.py')
-rw-r--r--src/index_service.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/index_service.py b/src/index_service.py
new file mode 100644
index 0000000..5038fce
--- /dev/null
+++ b/src/index_service.py
@@ -0,0 +1,27 @@
1from whoosh import index
2from whoosh.qparser import MultifieldParser
3
4import bottle
5from bottle import route, run, request
6
7
8@route('/search')
9def search():
10 term = request.query.get("q")
11
12 if not term:
13 return { 'error': 'No search term specified' }
14
15 idx = index.open_dir("indexdir")
16 parser = MultifieldParser(
17 ["track_name", "artist", "album"], schema=idx.schema)
18
19 with idx.searcher() as searcher:
20 results = searcher.search(parser.parse(term))
21 return { 'results': [dict(result) for result in results] }
22
23bottle.debug(True)
24app = bottle.default_app()
25
26#if __name__ == "__main__":
27run(host='localhost', port=8080)