Add support for ts_headline
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)
Owner: |
set to Hannes Ljungberg
|
Status: |
new → assigned
|
Triage Stage: |
Unreviewed → Accepted
|
Patch needs improvement: |
set
|
Patch needs improvement: |
unset
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
PR: https://github.com/django/django/pull/12297