Commit 8823ccab by David Guillot

[Model] Document : faire du champ notice_numero un string searchable

parent 1b9de7c8
......@@ -18,11 +18,80 @@ depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('documents', sa.Column('notice_numero', sa.Integer(), nullable=True))
op.add_column('documents', sa.Column('notice_numero', sa.String(10), nullable=True))
conn = op.get_bind()
conn.execute("""
CREATE OR REPLACE FUNCTION public.documents_search_vector_update()
RETURNS trigger AS
$BODY$
BEGIN
NEW.search_vector =
(
(
(
(
(
(
to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.titre, ''), '[-@.]', ' ', 'g'))
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.type_code, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.type_libelle, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.soustype_code, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.soustype_libelle, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.statut_adoption, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.denomination_structurelle, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.notice_numero, ''), '[-@.]', ' ', 'g'))
;
RETURN NEW;
END
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION public.documents_search_vector_update()
OWNER TO parlapi;
""")
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
conn.execute("""
CREATE OR REPLACE FUNCTION public.documents_search_vector_update()
RETURNS trigger AS
$BODY$
BEGIN
NEW.search_vector =
(
(
(
(
(
to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.titre, ''), '[-@.]', ' ', 'g'))
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.type_code, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.type_libelle, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.soustype_code, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.soustype_libelle, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.statut_adoption, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.denomination_structurelle, ''), '[-@.]', ' ', 'g'))
;
RETURN NEW;
END
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION public.documents_search_vector_update()
OWNER TO parlapi;
""")
op.drop_column('documents', 'notice_numero')
# ### end Alembic commands ###
......@@ -53,7 +53,7 @@ class ImportDossiersJob(BaseANJob):
'divisions': [],
'dossier': None,
'legislature': None,
'notice_numero': notice['numNotice'],
'notice_numero': str(notice['numNotice']),
'organes': [],
'soustype_code': None,
'soustype_libelle': None,
......
......@@ -246,7 +246,7 @@ class Document(db.Model):
date_publication = db.Column(db.Date)
date_publication_web = db.Column(db.Date)
notice_numero = db.Column(db.Integer)
notice_numero = db.Column(db.String(10))
titre = db.Column(db.Unicode)
denomination_structurelle = db.Column(db.Unicode)
type_code = db.Column(db.Unicode)
......@@ -276,8 +276,9 @@ class Document(db.Model):
dossier_id = db.Column(db.Unicode, db.ForeignKey('dossiers.id'))
dossier = db.relationship('Dossier', back_populates='documents')
search_vector = db.Column(TSVectorType('titre', 'type_code',
'type_libelle', 'soustype_code',
search_vector = db.Column(TSVectorType('titre', 'notice_numero',
'type_code', 'type_libelle',
'soustype_code',
'soustype_libelle',
'statut_adoption',
'denomination_structurelle'))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment