0

I want to highlight search terms with SearchHeadline. My code is somethink like this:

query = SearchQuery('cat')
vector = SearchVector('caption')
Post.objects.annotate(
    search=vector
    headline=SearchHeadline(
        'caption',
        query
    )
).filter(search=query)

This code works well and for example the headline of the first result is:

'My <b>cat</b> breed is Persian. Persian cats are the most beautiful breed.'

As you can see cat is highlighted but cats is not, and I want to highlight all of cat string in the caption, like this:

'My <b>cat</b> breed is Persian. Persian <b>cat</b>s are the most beautiful breed.'

1 Answers1

0

you can use icontains to search the particular term in words and sentences.

query = SearchQuery('cat')
vector = SearchVector('caption')
Post.objects.annotate(
    search=vector
    headline=SearchHeadline(
        'caption',
        query
    )
).filter(search__icontains=query)
wheezay
  • 101
  • 7