-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve taxon search box #557
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,62 @@ | ||
-- Taxons observés et de tous leurs synonymes (utilisés pour la recherche d'une espèce) | ||
CREATE MATERIALIZED VIEW atlas.vm_search_taxon AS | ||
WITH verna_names AS ( | ||
SELECT DISTINCT | ||
cd_nom, | ||
lb_nom, | ||
cd_ref, | ||
STRING_TO_TABLE(nom_vern, ', ') AS nom_vern | ||
FROM atlas.vm_taxref | ||
WHERE nom_vern IS NOT NULL | ||
AND cd_nom = cd_ref | ||
AND nom_vern <> lb_nom | ||
), | ||
names AS ( | ||
-- Chosen scinames | ||
SELECT | ||
cd_nom, | ||
cd_ref, | ||
lb_nom AS search_name, | ||
CONCAT('<b>', REPLACE(nom_complet_html, lb_auteur, ''), '</b> ', lb_auteur) AS display_name | ||
FROM atlas.vm_taxref | ||
WHERE cd_nom = cd_ref | ||
|
||
CREATE MATERIALIZED VIEW atlas.vm_search_taxon AS | ||
SELECT row_number() OVER (ORDER BY t.cd_nom,t.cd_ref,t.search_name)::integer AS fid, | ||
t.cd_nom, | ||
t.cd_ref, | ||
t.search_name, | ||
t.nom_valide, | ||
t.lb_nom | ||
FROM ( | ||
SELECT t_1.cd_nom, | ||
t_1.cd_ref, | ||
concat(t_1.lb_nom, ' = <i> ', t_1.nom_valide, '</i>') AS search_name, | ||
t_1.nom_valide, | ||
t_1.lb_nom | ||
FROM atlas.vm_taxref t_1 | ||
UNION | ||
|
||
UNION | ||
SELECT t_1.cd_nom, | ||
t_1.cd_ref, | ||
concat(t_1.nom_vern, ' = <i> ', t_1.nom_valide, '</i>' ) AS search_name, | ||
t_1.nom_valide, | ||
t_1.lb_nom | ||
FROM atlas.vm_taxref t_1 | ||
WHERE t_1.nom_vern IS NOT NULL AND t_1.cd_nom = t_1.cd_ref | ||
) t | ||
JOIN atlas.vm_taxons taxons ON taxons.cd_ref = t.cd_ref; | ||
-- Synonym scinames | ||
SELECT | ||
t1.cd_nom, | ||
t1.cd_ref, | ||
t1.lb_nom AS search_name, | ||
CONCAT(REPLACE(t1.nom_complet_html, t1.lb_auteur, ''), ' = <b> ', REPLACE(t2.nom_complet_html, t2.lb_auteur, ''), '</b> ', t2.lb_auteur) AS display_name | ||
FROM atlas.vm_taxref AS t1 | ||
JOIN atlas.vm_taxref AS t2 | ||
ON t1.cd_ref = t2.cd_nom | ||
WHERE t1.cd_nom <> t1.cd_ref | ||
|
||
UNION | ||
|
||
-- Vernacular names | ||
SELECT | ||
v.cd_nom, | ||
v.cd_ref, | ||
v.nom_vern AS search_name, | ||
CONCAT(v.nom_vern, ' = <b> ', REPLACE(t.nom_complet_html, t.lb_auteur, ''), '</b> ', t.lb_auteur) AS display_name | ||
FROM verna_names AS v | ||
JOIN atlas.vm_taxref AS t | ||
ON t.cd_nom = v.cd_ref | ||
WHERE v.nom_vern <> v.lb_nom | ||
) | ||
SELECT ROW_NUMBER() OVER (ORDER BY n.cd_nom, n.cd_ref, n.search_name)::integer AS fid, | ||
n.cd_nom, | ||
n.cd_ref, | ||
n.search_name, | ||
n.display_name | ||
FROM atlas.vm_taxons AS t | ||
JOIN names AS n | ||
ON t.cd_ref = n.cd_ref ; | ||
|
||
CREATE UNIQUE INDEX ON atlas.vm_search_taxon(fid); | ||
CREATE INDEX ON atlas.vm_search_taxon(cd_nom); | ||
create INDEX ON atlas.vm_search_taxon(cd_ref); | ||
|
||
CREATE INDEX ON atlas.vm_search_taxon(cd_ref); | ||
CREATE INDEX trgm_idx ON atlas.vm_search_taxon USING GIST (search_name gist_trgm_ops); | ||
CREATE UNIQUE INDEX ON atlas.vm_search_taxon (cd_nom, search_name); | ||
CREATE UNIQUE INDEX ON atlas.vm_search_taxon (cd_nom, search_name); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,3 +43,72 @@ CREATE INDEX ON atlas.vm_observations_mailles | |
|
||
CREATE INDEX ON atlas.vm_observations_mailles | ||
USING btree (id_maille, cd_ref); | ||
|
||
|
||
-- ISSUE #531 & #532 | ||
CREATE EXTENSION IF NOT EXISTS unaccent SCHEMA "public"; | ||
|
||
-- ISSUE #532 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Il est également nécessaire de donner les droits à l'utilisateur en lecture seule de l'Atlas (habituellement GRANT SELECT ON TABLE atlas.vm_search_taxon TO geonatatlas; Vue que le nom de cet utilisateur est configurable et que l'accès au paramètre de config n'est pas possible, comment doit-on procéder ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je mettrais une note spécifique dans le changelog, indiquant la commande à lancer manuellement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Tu veux dire que je peux modifier le fichier https://github.com/PnX-SI/GeoNature-atlas/blob/master/docs/changelog.rst ? Ou c'est à faire uniquement lors de la création de la nouvelle release ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oui c'est bien de compléter le Changelog au fur et à mesure dans les PR, ça rend les merge un peu plus complexe, mais on s'en charge. |
||
DROP MATERIALIZED VIEW IF EXISTS atlas.vm_search_taxon ; | ||
CREATE MATERIALIZED VIEW atlas.vm_search_taxon AS | ||
WITH verna_names AS ( | ||
SELECT DISTINCT | ||
cd_nom, | ||
lb_nom, | ||
cd_ref, | ||
STRING_TO_TABLE(nom_vern, ', ') AS nom_vern | ||
FROM atlas.vm_taxref | ||
WHERE nom_vern IS NOT NULL | ||
AND cd_nom = cd_ref | ||
AND nom_vern <> lb_nom | ||
), | ||
names AS ( | ||
-- Chosen scinames | ||
SELECT | ||
cd_nom, | ||
cd_ref, | ||
lb_nom AS search_name, | ||
CONCAT('<b>', REPLACE(nom_complet_html, lb_auteur, ''), '</b> ', lb_auteur) AS display_name | ||
FROM atlas.vm_taxref | ||
WHERE cd_nom = cd_ref | ||
|
||
UNION | ||
|
||
-- Synonym scinames | ||
SELECT | ||
t1.cd_nom, | ||
t1.cd_ref, | ||
t1.lb_nom AS search_name, | ||
CONCAT(REPLACE(t1.nom_complet_html, t1.lb_auteur, ''), ' = <b> ', REPLACE(t2.nom_complet_html, t2.lb_auteur, ''), '</b> ', t2.lb_auteur) AS display_name | ||
FROM atlas.vm_taxref AS t1 | ||
JOIN atlas.vm_taxref AS t2 | ||
ON t1.cd_ref = t2.cd_nom | ||
WHERE t1.cd_nom <> t1.cd_ref | ||
|
||
UNION | ||
|
||
-- Vernacular names | ||
SELECT | ||
v.cd_nom, | ||
v.cd_ref, | ||
v.nom_vern AS search_name, | ||
CONCAT(v.nom_vern, ' = <b> ', REPLACE(t.nom_complet_html, t.lb_auteur, ''), '</b> ', t.lb_auteur) AS display_name | ||
FROM verna_names AS v | ||
JOIN atlas.vm_taxref AS t | ||
ON t.cd_nom = v.cd_ref | ||
WHERE v.nom_vern <> v.lb_nom | ||
) | ||
SELECT ROW_NUMBER() OVER (ORDER BY n.cd_nom, n.cd_ref, n.search_name)::integer AS fid, | ||
n.cd_nom, | ||
n.cd_ref, | ||
n.search_name, | ||
n.display_name | ||
FROM atlas.vm_taxons AS t | ||
JOIN names AS n | ||
ON t.cd_ref = n.cd_ref ; | ||
|
||
CREATE UNIQUE INDEX ON atlas.vm_search_taxon(fid); | ||
CREATE INDEX ON atlas.vm_search_taxon(cd_nom); | ||
CREATE INDEX ON atlas.vm_search_taxon(cd_ref); | ||
CREATE INDEX trgm_idx ON atlas.vm_search_taxon USING GIST (search_name gist_trgm_ops); | ||
CREATE UNIQUE INDEX ON atlas.vm_search_taxon (cd_nom, search_name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avec
SRING_TO_TABLE
on ne pourra plus rechercher sur tous les noms vernaculaires, je pense que c'est dommage. Il me semble que que le split n'était fait que sur la fiche espèce, pour de l'affichageThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oups j'avais pas vu la différence entre
search_name
etdisplay_name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normalement, c'est fonctionnel. J'ai mis en prod cette PR sur les 2 Atlas des SINP PACA et AURA, si tu veux vérifier certains points : https://nature.silene.eu/ et https://atlas.biodiversite-auvergne-rhone-alpes.fr/
Est ce que tu penses que j'ai loupé quelque chose ?