This commit is contained in:
2020-05-20 22:43:23 +00:00
parent 64b61d14fa
commit b2fb544f7f
2 changed files with 44 additions and 19 deletions

View File

@@ -16,44 +16,39 @@ https://www.postgresqltutorial.com/plpgsql-loop-statements/
-- DROP PROCEDURE public.pdoindex(text[], bigint, integer, boolean);
CREATE OR REPLACE PROCEDURE public.pdoindex(
words text[],
objectid bigint,
objecttype integer,
isupdate boolean DEFAULT false)
CREATE OR REPLACE PROCEDURE public.aydosearchindex(
wordlist text[],
ayobjectid bigint,
ayobjecttype integer)
LANGUAGE 'plpgsql'
AS $BODY$DECLARE
s text;
wordid bigint;
BEGIN
IF objectid=0 THEN
RAISE EXCEPTION 'Bad object id --> %', objectid;
IF ayobjectid=0 THEN
RAISE EXCEPTION 'Bad object id --> %', ayobjectid;
END IF;
IF objecttype=0 THEN
RAISE EXCEPTION 'Bad object type --> %', objecttype;
IF ayobjecttype=0 THEN
RAISE EXCEPTION 'Bad object type --> %', ayobjecttype;
END IF;
-- insert into asearchdictionary (word) values('{0}') on conflict (word) do update set word=excluded.word returning *
-- iterate text in loop
FOREACH s IN ARRAY words
delete from asearchkey where objectid=ayobjectid and objecttype=ayobjecttype;
FOREACH s IN ARRAY wordlist
LOOP
insert into asearchdictionary (word) values(s) on conflict (word) do update set word=excluded.word returning id into wordid;
insert into asearchkey (wordid,objectid,objecttype) values(wordid,objectid,objecttype);
--RAISE info 'word is %', s;
--RAISE info 'word id is %', wordid;
insert into asearchkey (wordid,objectid,objecttype) values(wordid,ayobjectid,ayobjecttype);
END LOOP;
END;
$BODY$;
------
call aydosearchindex(ARRAY['sun','mon','tue','wed','thu','fri','sat'],3,3)
-------
ALTER FUNCTION public.doindex(text[], bigint, integer, boolean)
OWNER TO postgres;
todo: Search confirm indexes are actually being used