|
|
@ -33,12 +33,12 @@ def generate_random_rgb(): |
|
|
|
b = get_random(0, 255) |
|
|
|
return r, g, b |
|
|
|
|
|
|
|
def insert_query_highlight(query, sentence, r, g, b): |
|
|
|
def insert_query_highlight(query, tfidf, sentence, r, g, b): |
|
|
|
pattern = r'[\s\W\_]'+query+r'[\s\W\_]|^'+query+'|'+query+'$' |
|
|
|
match = re.search(pattern, sentence, flags=re.IGNORECASE) |
|
|
|
if match: |
|
|
|
match = match.group() |
|
|
|
sentence = re.sub(pattern, ' <strong class="query" style="color:rgba({r},{g},{b},1); background-image: radial-gradient(ellipse, rgba({r},{g},{b},0.4), rgba({r},{g},{b},0.2), transparent, transparent);">{match}</strong> '.format(match=match, r=r, b=b, g=g), sentence, flags=re.IGNORECASE) |
|
|
|
match = match.group().replace(' ', '') |
|
|
|
sentence = re.sub(pattern, ' <strong class="query" style="font-size:{tfidf}%;color:rgba({r},{g},{b},1); background-image: radial-gradient(ellipse, rgba({r},{g},{b},0.4), rgba({r},{g},{b},0.2), transparent, transparent);">{match}</strong> '.format(tfidf=tfidf, match=match, r=r, b=b, g=g), sentence, flags=re.IGNORECASE) |
|
|
|
return sentence |
|
|
|
|
|
|
|
def insert_suggestion_links(query, sentence): |
|
|
@ -159,7 +159,7 @@ def request_results(query): |
|
|
|
results[x]['matches'].append(sentence) |
|
|
|
|
|
|
|
# Transform sentence into an HTML elements |
|
|
|
html = insert_query_highlight(query, sentence, r, g, b) |
|
|
|
html = insert_query_highlight(query.strip(), 100 + (tfidf * multiplier), sentence, r, g, b) |
|
|
|
html = insert_suggestion_links(query, html) |
|
|
|
html = Markup(html) |
|
|
|
results[x]['html'].append(html) |
|
|
|