X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/6535d2e28106edd90589a6a2376cf52a796adf3e..6407cf24cd6cf3f9ea6fdf4a8924dad109a590e6:/src/catalogue/models/snippet.py diff --git a/src/catalogue/models/snippet.py b/src/catalogue/models/snippet.py index 3c9384cc7..4c25b8c97 100644 --- a/src/catalogue/models/snippet.py +++ b/src/catalogue/models/snippet.py @@ -1,23 +1,27 @@ from django.db import models +from django.contrib.postgres.indexes import GinIndex from django.contrib.postgres.search import SearchVector, SearchVectorField -from search.utils import build_search_vector +from search.utils import UnaccentSearchVector class Snippet(models.Model): book = models.ForeignKey('Book', models.CASCADE) sec = models.IntegerField() - # header_type ? - # header_span ? text = models.TextField() search_vector = SearchVectorField() + class Meta: + indexes = [ + GinIndex('search_vector', name='search_vector_idx'), + ] + def save(self, *args, **kwargs): super().save(*args, **kwargs) if not self.search_vector: self.update() def update(self): - self.search_vector = build_search_vector('text') + self.search_vector = UnaccentSearchVector('text') self.save() @classmethod