summaryrefslogtreecommitdiff
path: root/src/index_service.py
diff options
context:
space:
mode:
authorMike Crute <mcrute@gmail.com>2015-07-29 18:38:22 -0700
committerMike Crute <mcrute@gmail.com>2015-07-29 18:38:22 -0700
commit53335ce936e758b816cce584665d1d55914b4ef4 (patch)
tree3822198638830ea0894ba06136a0e29cea7c05b9 /src/index_service.py
downloadaudiocloud-master.tar.bz2
audiocloud-master.tar.xz
audiocloud-master.zip
Initial importHEADmaster
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)