-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalvinball.py
More file actions
32 lines (25 loc) · 982 Bytes
/
Copy pathcalvinball.py
File metadata and controls
32 lines (25 loc) · 982 Bytes
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
28
29
30
31
32
from flask import Flask, jsonify, render_template, request, url_for, g
app = Flask(__name__)
from whoosh.index import open_dir
from whoosh.qparser import QueryParser
from whoosh import highlight
from datetime import datetime
ix=open_dir("index")
brf = highlight.HtmlFormatter()
def find(query):
with ix.searcher() as searcher:
query = QueryParser("transcript", ix.schema).parse(query)
results = searcher.search(query)
results.fragmenter=highlight.WholeFragmenter()
results.formatter = brf
return [dict(url=result['url'],summary=result.highlights('transcript'),date=datetime.strftime(result['date'],'%b %d %Y'),transcript=result['transcript']) for result in results]
@app.route('/')
def index():
return render_template('index.html')
@app.route('/search')
def search():
query = request.args.get('query')
results=find(query)
return jsonify(results)
# if __name__ == '__main__':
# app.run(host='0.0.0.0',debug=True)