Update app.py
Browse files
app.py
CHANGED
@@ -7,24 +7,6 @@ from opensearchpy import OpenSearch, RequestsHttpConnection
|
|
7 |
from requests_aws4auth import AWS4Auth
|
8 |
|
9 |
|
10 |
-
awsauth = AWS4Auth(
|
11 |
-
os.environ.get("ACCESS_KEY"),
|
12 |
-
os.environ.get("SECRET_KEY"),
|
13 |
-
"us-east-1",
|
14 |
-
"es",
|
15 |
-
)
|
16 |
-
|
17 |
-
es = OpenSearch(
|
18 |
-
hosts=[{"host": os.environ.get("HOST"), "port": 443}],
|
19 |
-
http_auth=awsauth,
|
20 |
-
use_ssl=True,
|
21 |
-
verify_certs=True,
|
22 |
-
connection_class=RequestsHttpConnection,
|
23 |
-
http_compress=True,
|
24 |
-
timeout=200,
|
25 |
-
)
|
26 |
-
|
27 |
-
|
28 |
def mark_tokens_bold(text, tokens):
|
29 |
for token in tokens:
|
30 |
if token in ["<", "b", "/", ">"]:
|
@@ -88,7 +70,24 @@ def phrase_query(query, num_results=10):
|
|
88 |
|
89 |
|
90 |
def search(query, num_results=10):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
print(es.ping())
|
|
|
92 |
query = query[:200]
|
93 |
if query.startswith('"') and query.endswith('"'):
|
94 |
response = phrase_query(query[1:-1], num_results=num_results)
|
|
|
7 |
from requests_aws4auth import AWS4Auth
|
8 |
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
def mark_tokens_bold(text, tokens):
|
11 |
for token in tokens:
|
12 |
if token in ["<", "b", "/", ">"]:
|
|
|
70 |
|
71 |
|
72 |
def search(query, num_results=10):
|
73 |
+
awsauth = AWS4Auth(
|
74 |
+
os.environ.get("ACCESS_KEY"),
|
75 |
+
os.environ.get("SECRET_KEY"),
|
76 |
+
"us-east-1",
|
77 |
+
"es",
|
78 |
+
)
|
79 |
+
|
80 |
+
es = OpenSearch(
|
81 |
+
hosts=[{"host": os.environ.get("HOST"), "port": 443}],
|
82 |
+
http_auth=awsauth,
|
83 |
+
use_ssl=True,
|
84 |
+
verify_certs=True,
|
85 |
+
connection_class=RequestsHttpConnection,
|
86 |
+
http_compress=True,
|
87 |
+
timeout=200,
|
88 |
+
)
|
89 |
print(es.ping())
|
90 |
+
|
91 |
query = query[:200]
|
92 |
if query.startswith('"') and query.endswith('"'):
|
93 |
response = phrase_query(query[1:-1], num_results=num_results)
|