-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
31 lines (25 loc) · 893 Bytes
/
server.py
File metadata and controls
31 lines (25 loc) · 893 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
from flask import Flask, render_template, request
import search
from time import time
app = Flask(__name__, template_folder='.')
@app.route('/', methods=['GET'])
def index():
start_time = time()
query = request.args.get('query')
if query is None:
query = ''
article_indices = search.retrieve_indices(query)
scored = [(search.articles[article_ind], search.scorer.score(query, article_ind))
for article_ind in article_indices]
scored = sorted(scored, key=lambda doc: -doc[1])
results = [doc.format(query)+['%.2f' % scr] + [doc.url] for doc, scr in scored]
return render_template(
'index.html',
time="%.2f" % (time()-start_time),
query=query,
search_engine_name='Pelmen',
results=results
)
if __name__ == '__main__':
search.build_search()
app.run(debug=True, host='0.0.0.0', port=80)