Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -12,7 +12,11 @@ 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(string,
|
|
|
|
|
|
|
|
|
16 |
for token in tokens:
|
17 |
pattern = re.escape(token) #r"\b" + re.escape(token) + r"\b"
|
18 |
string = re.sub(pattern, "<span style='color: #e6b800;'><b>" + token + "</b></span>", string)
|
@@ -26,7 +30,7 @@ def process_results(results, query):
|
|
26 |
results_html = ""
|
27 |
for result in results:
|
28 |
text_html = result["text"]
|
29 |
-
text_html = mark_tokens_bold(text_html, query
|
30 |
repository = result['repository']
|
31 |
license = result["license"]
|
32 |
language = result["language"]
|
|
|
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(string, query):
|
16 |
+
if query.startswith('"') and query.endswith('"'):
|
17 |
+
tokens = query
|
18 |
+
else:
|
19 |
+
tokens = query.split(" ")
|
20 |
for token in tokens:
|
21 |
pattern = re.escape(token) #r"\b" + re.escape(token) + r"\b"
|
22 |
string = re.sub(pattern, "<span style='color: #e6b800;'><b>" + token + "</b></span>", string)
|
|
|
30 |
results_html = ""
|
31 |
for result in results:
|
32 |
text_html = result["text"]
|
33 |
+
text_html = mark_tokens_bold(text_html, query)
|
34 |
repository = result['repository']
|
35 |
license = result["license"]
|
36 |
language = result["language"]
|