-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOnlineApp.py
More file actions
74 lines (64 loc) · 2.33 KB
/
OnlineApp.py
File metadata and controls
74 lines (64 loc) · 2.33 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
from elasticsearch import Elasticsearch
from json import dumps
es = Elasticsearch("AWS Elasticsearch Cluster API URI")
##################################################################################################################################
from flask import Flask
from flask import request
from flask import render_template, redirect, url_for
app = Flask(__name__)
@app.route('/',methods = ['GET','POST'])
def index():
if request.method == 'GET':
return render_template("home.html")
else:
query = request.form['text']
return redirect(url_for('search', query = query))
@app.route('/search/news/?=<query>', methods = ['GET', 'POST'])
def search(query):
if request.method == 'GET':
searchDoc = {
"size": 18,
"query": {
"dis_max": {
"queries": [
{
"match": {
"title": {
"query": query,
"boost": 2
}
}
},
{
"match": {
"description": {
"query": query,
"boost": 1.5
}
}
},
{
"match": {
"keywords": {
"query": query,
"boost": 1.2
}
}
}
]
}
},
"sort": [
{ "_score": { "order": "desc" }},
{ "date": { "order": "desc" }}
]
}
results = es.search(index = "hsse", doc_type = "doc", body = dumps(searchDoc), sort = "_score")
return render_template('search_results.html', results = results, search_text = query)
else:
return "Some Error Occured!"
if __name__ == '__main__':
app.secret_key = 'Some Secret Key'
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port, debug = True)