-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
40 lines (29 loc) · 926 Bytes
/
app.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
29
30
31
32
33
34
35
36
37
38
39
40
from flask import Flask, request
from flask import render_template
from run import index_documents
from indexing_and_searching.indexing import Index
from indexing_and_searching.loading import load_documents
app = Flask(__name__)
# background task
def background():
return index_documents(load_documents(), Index())
# first page of the website
@app.route('/')
def my_form():
return render_template('form.html')
index = background()
@app.route('/', methods=['POST'])
def my_form_post():
if index:
searching_keyword = request.form['variable']
try:
results = index.search(searching_keyword)
except:
print(index.search(searching_keyword))
finally:
return render_template('form.html', results=results)
if __name__ == '__main__':
thread = Thread(target=background)
thread.daemon = True
thread.start()
app.run()