Skip to content

Commit

Permalink
Show first match instead of last in search results
Browse files Browse the repository at this point in the history
  • Loading branch information
Mortal committed Aug 5, 2018
1 parent 055dd13 commit d45b4c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/wiki/templatetags/wiki_tags.py
Expand Up @@ -116,7 +116,7 @@ def clean_text(content):

max_words = int(max_words)

match_position = content.lower().rfind(keyword.lower())
match_position = content.lower().find(keyword.lower())

if match_position != -1:
try:
Expand Down
26 changes: 6 additions & 20 deletions tests/core/test_template_filters.py
Expand Up @@ -40,18 +40,9 @@ def test_keyword_at_the_beginning_of_the_content(self):

self.assertEqual(output, expected)

def test_whole_content_is_consist_from_keywords(self):
def test_whole_content_consists_of_keywords(self):
content = 'lorem ' * 80
expected = (
'<strong>lorem</strong> <strong>lorem</strong> '
'<strong>lorem</strong> <strong>lorem</strong> '
'<strong>lorem</strong> <strong>lorem</strong> '
'<strong>lorem</strong> <strong>lorem</strong> '
'<strong>lorem</strong> <strong>lorem</strong> '
'<strong>lorem</strong> <strong>lorem</strong> '
'<strong>lorem</strong> <strong>lorem</strong> '
'<strong>lorem</strong> <strong>lorem</strong>'
)
expected = '<strong>lorem</strong>' + 30 * ' <strong>lorem</strong>'

output = get_content_snippet(content, 'lorem')

Expand Down Expand Up @@ -79,11 +70,7 @@ def test_a_few_keywords_in_content(self):
text = 'dolorum ' * 80
content += text + ' list'

expected = (
'dolorum dolorum dolorum dolorum dolorum dolorum dolorum '
'dolorum dolorum dolorum dolorum dolorum dolorum dolorum dolorum '
'<strong>list</strong>'
)
expected = '<strong>list</strong>' + 30 * ' lorem'

output = get_content_snippet(content, 'list')

Expand Down Expand Up @@ -145,8 +132,7 @@ def test_strip_tags(self):
keyword = 'maybe'

content = """
<h1>Some dummy</h1> text. <div>Actually</div> I don't what to write,
heh. Don't now, <b>maybe</b> I should citate Shakespeare or Byron.
I should citate Shakespeare or Byron.
Or <a>maybe</a> copy paste from <a href="http://python.org">python</a>
or django documentation. Maybe.
"""
Expand All @@ -168,8 +154,8 @@ def test_max_words_arg(self):
content = """
knight eggs spam ham eggs guido python eggs circus
"""
expected = ('<strong>eggs</strong> guido python '
'<strong>eggs</strong> circus')
expected = ('knight <strong>eggs</strong> spam ham '
'<strong>eggs</strong> guido')

output = get_content_snippet(content, keyword, 5)

Expand Down

0 comments on commit d45b4c0

Please sign in to comment.