Can you specify SearchVector
weights with UpdateSearchVector
?
#210
-
Is there a way to specify SearchVector weights with import pgtrigger
from django.contrib.postgres.indexes import GinIndex
from django.contrib.postgres.search import SearchVector, SearchVectorField
from django.db import models
# example configuration of a model
class Items(models.Model):
name = models.CharField(_("name"), max_length=100, db_index=True)
description = models.CharField(_("description"), max_length=500, default="", blank=True)
search_vector = SearchVectorField(null=True)
class Meta:
indexes = (GinIndex(fields=["search_vector"]),)
triggers = [
pgtrigger.UpdateSearchVector(
name="add_name_desc_to_vector",
vector_field="search_vector",
document_fields=["name", "description"],
),
]
# example update by hand
Exercise.objects.update(
search_vector=(
SearchVector('name', weight='A') +
SearchVector('description', weight='B')
)
) |
Beta Was this translation helpful? Give feedback.
Answered by
wesleykendall
May 15, 2025
Replies: 1 comment
-
pgtrigger is calling Postgres's tsvector_update_trigger utility function. This function does not seem to support adding weights to each column to the best of my knowledge. If you want to sync a vector with weighted fields, your best bet for now is to write a custom trigger to do that |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
mrcoles
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pgtrigger is calling Postgres's tsvector_update_trigger utility function. This function does not seem to support adding weights to each column to the best of my knowledge.
If you want to sync a vector with weighted fields, your best bet for now is to write a custom trigger to do that