Skip to content

add to README tutorial something on Headline #4

@eukreign

Description

@eukreign

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')
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions