Opened 5 years ago

Closed 5 years ago

#31147 closed New feature (fixed)

Add support for ts_headline

Reported by: Hannes Ljungberg Owned by: Hannes Ljungberg
Component: contrib.postgres Version: dev
Severity: Normal Keywords: postgres search ts_headline
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It would be nice to get support for the Postgres full text search function ts_headline. See https://www.postgresql.org/docs/current/textsearch-controls.html#TEXTSEARCH-HEADLINE

SearchHeadline would also accept an optional options argument which is a where configuration options like StartSel and StopSel can be specified.

My proposed implementation work look like this:

>>> from django.contrib.postgres.search import SearchHeadline, SearchQuery
>>> query = SearchQuery('brave sir robin')
>>> first_line = Line.objects.annotate(
...     headline=SearchHeadline('dialogue', query, options={
...         'StartSel': '<b>',
...         'StopSel': '</b>'
...     })
... ).first()
>>> print(first_line.headline)
'<b>Robin</b>. He was not at all afraid to be killed in nasty ways. <b>Brave</b>, <b>brave</b>, <b>brave</b>, <b>brave</b> <b>Sir</b> <b>Robin</b>'

I have this implementation ready if this would be accepted: https://github.com/django/django/compare/master...hannseman:ts_headline?expand=1

Change History (7)

comment:1 by Hannes Ljungberg, 5 years ago

Owner: set to Hannes Ljungberg
Status: newassigned

comment:2 by Simon Charette, 5 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Hannes Ljungberg, 5 years ago

Has patch: set

comment:4 by Mariusz Felisiak, 5 years ago

Patch needs improvement: set

comment:5 by Hannes Ljungberg, 5 years ago

Patch needs improvement: unset

comment:6 by Mariusz Felisiak, 5 years ago

Triage Stage: AcceptedReady for checkin

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 65ab4f9f:

Fixed #31147 -- Added SearchHeadline to django.contrib.postgres.

Note: See TracTickets for help on using tickets.
Back to Top