Defines the GIN search index in the models.

pull/3940/head
Bertrand Bordage 2017-10-19 15:17:40 +01:00
rodzic 74aaa91ef6
commit bfbc7adcab
2 zmienionych plików z 8 dodań i 1 usunięć

Wyświetl plik

@ -44,5 +44,11 @@ class Migration(migrations.Migration):
'CREATE INDEX {0}_body_search ON {0} '
'USING GIN(body_search);'.format(table),
'DROP INDEX {}_body_search;'.format(table),
state_operations=[migrations.AddIndex(
model_name='indexentry',
index=django.contrib.postgres.indexes.GinIndex(
fields=['body_search'],
name='postgres_se_body_se_70ba1a_gin'),
)],
),
]

Wyświetl plik

@ -3,6 +3,7 @@ from __future__ import absolute_import, unicode_literals
from django.apps import apps
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.contrib.postgres.indexes import GinIndex
from django.contrib.postgres.search import SearchVectorField
from django.db.models import CASCADE, ForeignKey, Model, TextField
from django.db.models.functions import Cast
@ -53,7 +54,7 @@ class IndexEntry(Model):
unique_together = ('content_type', 'object_id')
verbose_name = _('index entry')
verbose_name_plural = _('index entries')
# TODO: Move here the GIN index from the migration.
indexes = [GinIndex(['body_search'])]
def __str__(self):
return '%s: %s' % (self.content_type.name, self.content_object)