Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions docs/ref/contrib/postgres/search.txt
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,31 @@ if it were an annotated ``SearchVector``:

.. _PostgreSQL documentation: https://www.postgresql.org/docs/current/textsearch-features.html#TEXTSEARCH-UPDATE-TRIGGERS

Using ``GeneratedField``
------------------------

An alternative method is to use a :class:`~django.db.models.GeneratedField`,
which has PostgreSQL maintain the column rather than a trigger::

from django.contrib.postgres.indexes import GinIndex
from django.contrib.postgres.search import SearchVector, SearchVectorField
from django.db import models


class Entry(models.Model):
headline = models.CharField(max_length=255)
body_text = models.TextField()

search_vector = models.GeneratedField(
expression=SearchVector("headline", weight="A", config="english")
+ SearchVector("body_text", weight="B", config="english"),
output_field=SearchVectorField(),
db_persist=True,
)

class Meta:
indexes = [GinIndex(fields=["search_vector"])]

Trigram similarity
==================

Expand Down
Loading