-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
28 lines (23 loc) · 806 Bytes
/
server.py
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
from flask import Flask, render_template, request
from search import score, retrieve, build_index, build_index_new
from time import time
app = Flask(__name__, template_folder='.')
build_index_new()
@app.route('/', methods=['GET'])
def index():
start_time = time()
query = request.args.get('query')
if query is None:
query = ''
documents = retrieve(query)
documents = sorted(documents, key=lambda doc: -score(query, doc))
results = [doc.format(query)+['%.2f' % score(query, doc)] for doc in documents]
return render_template(
'index.html',
time="%.2f" % (time()-start_time),
query=query,
search_engine_name='Neptun Compiuter',
results=results
)
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=80)