Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add to README tutorial something on Headline #4

Open
eukreign opened this issue Sep 14, 2017 · 1 comment
Open

add to README tutorial something on Headline #4

eukreign opened this issue Sep 14, 2017 · 1 comment

Comments

@eukreign
Copy link
Member

Update the README with some instructions on how to use the Headline class and present matched excerpts from the result set....

https://github.com/damoti/django-tsvector-field/blob/master/tsvector_field/query.py#L5

from django.db.models.expressions import F
from django.contrib.postgres.search import SearchRank, SearchQuery
import tsvector_field

query = SearchQuery(self.form['text'].value())
qs = (
  qs.filter(text__search=query)
    .annotate(
      match_title=tsvector_field.Headline(F('text__title'), query),
      match_text=tsvector_field.Headline(F('text__text'), query)
    )
    .annotate(rank=SearchRank(F('text__search'), query))
    .order_by('-rank')
)
@3lixy
Copy link

3lixy commented Jul 15, 2018

Many thanks for how to use Headline. I almost had it right but this ticket got it working for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants