forked from zaclys/searxng
[fix] query highlight fix
This commit is contained in:
parent
cbb397939d
commit
b9ebf18f59
|
@ -112,12 +112,14 @@ def highlight_content(content, query):
|
||||||
query_regex = '({0})'.format(re.escape(query))
|
query_regex = '({0})'.format(re.escape(query))
|
||||||
content = re.sub(query_regex, '<b>\\1</b>', content, flags=re.I)
|
content = re.sub(query_regex, '<b>\\1</b>', content, flags=re.I)
|
||||||
else:
|
else:
|
||||||
|
regex_parts = []
|
||||||
for chunk in query.split():
|
for chunk in query.split():
|
||||||
if len(chunk) == 1:
|
if len(chunk) == 1:
|
||||||
query_regex = '(\W+{0}\W+)'.format(re.escape(chunk))
|
regex_parts.append('\W+{0}\W+'.format(re.escape(chunk)))
|
||||||
else:
|
else:
|
||||||
query_regex = '({0})'.format(re.escape(chunk))
|
regex_parts.append('{0}'.format(re.escape(chunk)))
|
||||||
content = re.sub(query_regex, '<b>\\1</b>', content, flags=re.I)
|
query_regex = '({0})'.format('|'.join(regex_parts))
|
||||||
|
content = re.sub(query_regex, '<b>\\1</b>', content, flags=re.I)
|
||||||
|
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue