Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,15 +12,15 @@ from elasticsearch_dsl import Search, Q
|
|
| 12 |
|
| 13 |
# es = Elasticsearch(os.environ.get("host"), timeout=100, http_compress=True, maxsize=1000)
|
| 14 |
es = Elasticsearch(os.environ.get("host"), timeout=200)
|
| 15 |
-
def mark_tokens_bold(
|
| 16 |
if query.startswith('"') and query.endswith('"'):
|
| 17 |
tokens = query[1:-1]
|
| 18 |
else:
|
| 19 |
tokens = query.split(" ")
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
return
|
| 24 |
|
| 25 |
|
| 26 |
def process_results(results, query):
|
|
|
|
| 12 |
|
| 13 |
# es = Elasticsearch(os.environ.get("host"), timeout=100, http_compress=True, maxsize=1000)
|
| 14 |
es = Elasticsearch(os.environ.get("host"), timeout=200)
|
| 15 |
+
def mark_tokens_bold(text, query):
|
| 16 |
if query.startswith('"') and query.endswith('"'):
|
| 17 |
tokens = query[1:-1]
|
| 18 |
else:
|
| 19 |
tokens = query.split(" ")
|
| 20 |
+
for token in tokens:
|
| 21 |
+
pattern = re.escape(token) #r"\b" + re.escape(token) + r"\b"
|
| 22 |
+
text = re.sub(pattern, "<span style='color: #e6b800;'><b>" + token + "</b></span>", text)
|
| 23 |
+
return text
|
| 24 |
|
| 25 |
|
| 26 |
def process_results(results, query):
|