blob: 5038fce8f374a0b7a83b9468712124102ac2b113 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
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)
|