zoo_meta: ajoute une méthode utilitaire pour créer des index trigram (#19092)
This commit is contained in:
parent
0884695546
commit
efaafa575d
|
@ -87,6 +87,25 @@ class CommonSchema(models.Model):
|
|||
'WHERE schema_id = %s' % (key, self.id, table, expr, self.id))
|
||||
cursor.execute(sql)
|
||||
|
||||
def create_trigram_index(self, expr):
|
||||
from zoo.zoo_data.models import Entity, Relation
|
||||
|
||||
if isinstance(self, EntitySchema):
|
||||
table = Entity._meta.db_table
|
||||
elif isinstance(self, RelationSchema):
|
||||
table = Relation._meta.db_table
|
||||
else:
|
||||
raise NotImplementedError(self)
|
||||
|
||||
key = md5(expr).hexdigest()[:8]
|
||||
gin_sql = ('CREATE INDEX zoo_entity_%s_gin_%s_dynamic_idx ON %s USING gin ((%s) '
|
||||
'gin_trgm_ops) WHERE schema_id = %s' % (key, self.id, table, expr, self.id))
|
||||
gist_sql = ('CREATE INDEX zoo_entity_%s_gist_%s_dynamic_idx ON %s USING gist ((%s)'
|
||||
' gist_trgm_ops) WHERE schema_id = %s' % (key, self.id, table, expr, self.id))
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute(gin_sql)
|
||||
cursor.execute(gist_sql)
|
||||
|
||||
def rebuild_indexes(self):
|
||||
from zoo.zoo_data.models import Entity
|
||||
|
||||
|
|
Loading…
Reference in New Issue