-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve taxons search (unaccent, better display)
Resolve #532.
- Loading branch information
Showing
6 changed files
with
153 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters