mirror of
https://github.com/searxng/searxng.git
synced 2024-11-22 20:17:45 +01:00
[fix] utf8 content highlighting
This commit is contained in:
parent
d0427d9bae
commit
3755f437e4
@ -112,18 +112,19 @@ def highlight_content(content, query):
|
|||||||
if content.find('<') != -1:
|
if content.find('<') != -1:
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
query = query.decode('utf-8')
|
||||||
if content.lower().find(query.lower()) > -1:
|
if content.lower().find(query.lower()) > -1:
|
||||||
query_regex = '({0})'.format(re.escape(query))
|
query_regex = u'({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 | re.U)
|
||||||
else:
|
else:
|
||||||
regex_parts = []
|
regex_parts = []
|
||||||
for chunk in query.split():
|
for chunk in query.split():
|
||||||
if len(chunk) == 1:
|
if len(chunk) == 1:
|
||||||
regex_parts.append('\W+{0}\W+'.format(re.escape(chunk)))
|
regex_parts.append(u'\W+{0}\W+'.format(re.escape(chunk)))
|
||||||
else:
|
else:
|
||||||
regex_parts.append('{0}'.format(re.escape(chunk)))
|
regex_parts.append(u'{0}'.format(re.escape(chunk)))
|
||||||
query_regex = '({0})'.format('|'.join(regex_parts))
|
query_regex = u'({0})'.format('|'.join(regex_parts))
|
||||||
content = re.sub(query_regex, '<b>\\1</b>', content, flags=re.I)
|
content = re.sub(query_regex, '<b>\\1</b>', content, flags=re.I | re.U)
|
||||||
|
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user