diff options
author | asciimoo <asciimoo@gmail.com> | 2013-11-10 21:47:42 +0100 |
---|---|---|
committer | asciimoo <asciimoo@gmail.com> | 2013-11-10 21:47:42 +0100 |
commit | b9ebf18f598605695c28a3aa4f381c947397d7ee (patch) | |
tree | 53461f7c320c6eb6705917c0dc42d743b90181ea | |
parent | cbb397939db355fb53da6bcf6bd8a2627f7a9584 (diff) | |
download | searxng-b9ebf18f598605695c28a3aa4f381c947397d7ee.tar.gz searxng-b9ebf18f598605695c28a3aa4f381c947397d7ee.zip |
[fix] query highlight fix
-rw-r--r-- | searx/engines/__init__.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index c17a53f46..081b69d3e 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -112,12 +112,14 @@ def highlight_content(content, query): query_regex = '({0})'.format(re.escape(query)) content = re.sub(query_regex, '<b>\\1</b>', content, flags=re.I) else: + regex_parts = [] for chunk in query.split(): if len(chunk) == 1: - query_regex = '(\W+{0}\W+)'.format(re.escape(chunk)) + regex_parts.append('\W+{0}\W+'.format(re.escape(chunk))) else: - query_regex = '({0})'.format(re.escape(chunk)) - content = re.sub(query_regex, '<b>\\1</b>', content, flags=re.I) + regex_parts.append('{0}'.format(re.escape(chunk))) + query_regex = '({0})'.format('|'.join(regex_parts)) + content = re.sub(query_regex, '<b>\\1</b>', content, flags=re.I) return content |