toastdriven/django-haystack — pull request #757 by BertrandBordage (2013-03-19 15:55:24+00:00)
Title: Adds a margin around highlighted words.

As mentionned in #675, querying “jehovah” on this text:

> Making it worse? How can it be worse? Jehovah! Jehovah! Jehovah!
> I'm warning you! If you say "Jehovah" one more time (gets hit with rock)

highlights like this:

> … **Jehovah**! **Jehovah**! **Jehovah**!
> I'm warning you! If you say “ **Jehovah** ” one more time (gets hit with rock)

even if ``max_length`` is superior to the length of the text.

This pull request fixes that by adding a margin before and after the highlighted “window”. Of course, this new margin is calculated so that the returned highlighted text doesn't exceed ``max_length``.