added pids for fulltext search

This commit is contained in:
Michele Artini 2022-02-23 13:05:25 +01:00
parent 5ea73251e3
commit f30eeac80a
2 changed files with 4 additions and 3 deletions

View File

@ -648,7 +648,6 @@ GROUP BY o.id, o.name, o.city, o.country
ORDER BY o.name; ORDER BY o.name;
CREATE TABLE org_index_search(id text PRIMARY KEY, txt tsvector); CREATE TABLE org_index_search(id text PRIMARY KEY, txt tsvector);
CREATE INDEX org_index_search_txt_idx ON org_index_search(txt);
CREATE INDEX org_index_search_txt_gin_idx ON org_index_search USING gin(txt); CREATE INDEX org_index_search_txt_gin_idx ON org_index_search USING gin(txt);
CREATE OR REPLACE FUNCTION refresh_index_search() RETURNS bigint AS $$ CREATE OR REPLACE FUNCTION refresh_index_search() RETURNS bigint AS $$
@ -656,9 +655,10 @@ CREATE OR REPLACE FUNCTION refresh_index_search() RETURNS bigint AS $$
WITH d as ( WITH d as (
INSERT INTO org_index_search(id, txt) SELECT INSERT INTO org_index_search(id, txt) SELECT
o.id, o.id,
to_tsvector(o.id||' '||o.name||' '||array_to_string(array_agg(DISTINCT n.name), ' ','')||' '||array_to_string(array_agg(DISTINCT a.acronym), ' ','')||' '||array_to_string(array_agg(DISTINCT u.url), ' ','')) to_tsvector(o.id||' '||o.name||' '||array_to_string(array_agg(DISTINCT n.name), ' ','')||' '||array_to_string(array_agg(DISTINCT i.otherid), ' ','')||' '||array_to_string(array_agg(DISTINCT a.acronym), ' ','')||' '||array_to_string(array_agg(DISTINCT u.url), ' ',''))
FROM organizations o FROM organizations o
LEFT OUTER JOIN other_names n on (o.id = n.id) LEFT OUTER JOIN other_names n on (o.id = n.id)
LEFT OUTER JOIN other_ids i on (o.id = i.id)
LEFT OUTER JOIN acronyms a on (o.id = a.id) LEFT OUTER JOIN acronyms a on (o.id = a.id)
LEFT OUTER JOIN urls u on (o.id = u.id) LEFT OUTER JOIN urls u on (o.id = u.id)
GROUP BY o.id, o.name RETURNING * GROUP BY o.id, o.name RETURNING *
@ -680,9 +680,10 @@ CREATE OR REPLACE FUNCTION insert_or_update_index_search_trigger() RETURNS trigg
BEGIN BEGIN
INSERT INTO org_index_search(id, txt) (SELECT INSERT INTO org_index_search(id, txt) (SELECT
o.id, o.id,
to_tsvector(o.id||' '||o.name||' '||array_to_string(array_agg(DISTINCT n.name), ' ','')||' '||array_to_string(array_agg(DISTINCT a.acronym), ' ','')||' '||array_to_string(array_agg(DISTINCT u.url), ' ','')) to_tsvector(o.id||' '||o.name||' '||array_to_string(array_agg(DISTINCT n.name), ' ','')||' '||array_to_string(array_agg(DISTINCT i.otherid), ' ','')||' '||array_to_string(array_agg(DISTINCT a.acronym), ' ','')||' '||array_to_string(array_agg(DISTINCT u.url), ' ',''))
FROM organizations o FROM organizations o
LEFT OUTER JOIN other_names n on (o.id = n.id) LEFT OUTER JOIN other_names n on (o.id = n.id)
LEFT OUTER JOIN other_ids i on (o.id = i.id)
LEFT OUTER JOIN acronyms a on (o.id = a.id) LEFT OUTER JOIN acronyms a on (o.id = a.id)
LEFT OUTER JOIN urls u on (o.id = u.id) LEFT OUTER JOIN urls u on (o.id = u.id)
WHERE o.id = new.id WHERE o.id = new.id