{% highlight %} - bug

11 views
Skip to first unread message

RobertGawron

unread,
Dec 17, 2009, 3:16:47 PM12/17/09
to django-haystack
Hello haystack users/coders,

IMHO there is a bug in your highlighter, take a look:

{% highlight "xxxxxxxxxxxxx foo bbxxxxx foo" with "foo" max_length 5
html_tag "span" %}

this will produce "xxxxx..."

Substring started from 0 is incorrect in this case because there isn't
any keyword to highlight. IMHO this should return "...foo b..."
instead - it's much better substring because it contain highlighted
key. I made a little research and found (IMHO) problem in find_window
function in utils.py:

best_start = 0
best_end = self.max_length

# here you check if context is valid

for count, start in enumerate(words_found[:-1]):
# here search for substring with the highest keywords
density

return (best_start, best_end)


If you don't find better substring you should return susbstring
started from index of
occurrence of first keyword, not from 0.

IMHO this could be fixed by adding before this line:

for count, start in enumerate(words_found[:-1]):

this code:

best_start = words_found[:-1][0]
best_end = best_start + self.max_length

IMHO that behavior is a bug and should be fixed but if I'm wrong then
sorry about # confusion & please tell where I made mistake.


regards,
Robert Gawron

Daniel Lindsley

unread,
Dec 19, 2009, 3:32:45 AM12/19/09
to django-...@googlegroups.com
For the purposes of the mailing list, an issue was posted with the
same content and was fixed in SHA:
b03c9af9d541bb18994bc01afac7e1b66056b9fe. Perhaps lightly
backward-incompatible in the sense users' won't get the same text in
their search results, but this should be better than what they would
have seen in those cases.


Daniel

> --
>
> You received this message because you are subscribed to the Google Groups "django-haystack" group.
> To post to this group, send email to django-...@googlegroups.com.
> To unsubscribe from this group, send email to django-haysta...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-haystack?hl=en.
>
>
>

Reply all
Reply to author
Forward
0 new messages