I am wondering how to make django-haystack highlight template tag show more of the text preceeding the highlight?
It currently shows "highlighted text some other text here" where it must show a bit more of the previous context, like: "some other text here highlighted text some other text here"
Thanks.
I think the best approach would be to extend Highlighter as described in the docs.
Something like:
from haystack.utils import Highlighter
class ShowMoreTextHighlighter(Highlighter):
def find_window(self, highlight_locations):
their_start, their_end = super(ShowMoreTextHighlighter, self).find_window(highlight_locations)
# perform some clever operations here to find an earlier start location
my_start = their_start/2 # or just do something simple
return (my_start, their_end)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With