Merge pull request #2109 from ahmad-alkadri/fix/highlight-full-word

Standalone words highlighting for query result in non-CJK characters
This commit is contained in:
Alexandre Flament 2023-01-17 23:24:04 +01:00 committed by GitHub
commit 6d72ef3cbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 25 deletions

View file

@ -28,32 +28,33 @@ class TestWebUtils(SearxTestCase):
content = 'a'
query = 'test'
self.assertEqual(webutils.highlight_content(content, query), content)
self.assertEqual(webutils.highlight_content(content, query), 'a')
query = 'a test'
self.assertEqual(webutils.highlight_content(content, query), content)
self.assertEqual(webutils.highlight_content(content, query), '<span class="highlight">a</span>')
data = (
('" test "', 'a test string', 'a <span class="highlight">test</span> string'),
('"a"', 'this is a test string', 'this is<span class="highlight"> a </span>test string'),
('"a"', 'this is a test string', 'this is <span class="highlight">a</span> test string'),
(
'a test',
'this is a test string that matches entire query',
'this is <span class="highlight">a test</span> string that matches entire query',
'this is <span class="highlight">a</span> <span class="highlight">test</span> string that matches entire query',
),
(
'this a test',
'this is a string to test.',
(
'<span class="highlight">this</span> is<span class="highlight"> a </span>'
'string to <span class="highlight">test</span>.'
'<span class="highlight">this</span> is <span class="highlight">a</span> string to <span class="highlight">test</span>.'
),
),
(
'match this "exact phrase"',
'this string contains the exact phrase we want to match',
(
'<span class="highlight">this</span> string contains the <span class="highlight">exact</span>'
' <span class="highlight">phrase</span> we want to <span class="highlight">match</span>'
''.join(
[
'<span class="highlight">this</span> string contains the <span class="highlight">exact</span> ',
'<span class="highlight">phrase</span> we want to <span class="highlight">match</span>',
]
),
),
)