v3 of indexing test
This commit is contained in:
@@ -12,16 +12,9 @@ todo: Search indexing performance improvement and exception avoidance (Search.cs
|
||||
stored procedure?
|
||||
https://www.postgresqltutorial.com/plpgsql-loop-statements/
|
||||
-------
|
||||
-- PROCEDURE: public.pdoindex(text[], bigint, integer, boolean)
|
||||
|
||||
-- DROP PROCEDURE public.pdoindex(text[], bigint, integer, boolean);
|
||||
|
||||
CREATE OR REPLACE PROCEDURE public.aydosearchindex(
|
||||
wordlist text[],
|
||||
ayobjectid bigint,
|
||||
ayobjecttype integer)
|
||||
LANGUAGE 'plpgsql'
|
||||
|
||||
CREATE OR REPLACE PROCEDURE public.aydosearchindex(wordlist text[], ayobjectid bigint, ayobjecttype integer, cleanfirst boolean)
|
||||
LANGUAGE 'plpgsql'
|
||||
|
||||
AS $BODY$DECLARE
|
||||
s text;
|
||||
wordid bigint;
|
||||
@@ -35,12 +28,24 @@ BEGIN
|
||||
END IF;
|
||||
|
||||
|
||||
delete from asearchkey where objectid=ayobjectid and objecttype=ayobjecttype;
|
||||
IF cleanfirst=true THEN
|
||||
delete from asearchkey where objectid=ayobjectid and objecttype=ayobjecttype;
|
||||
END IF;
|
||||
|
||||
FOREACH s IN ARRAY wordlist
|
||||
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,ayobjectid,ayobjecttype);
|
||||
raise info 'processing word %',s;
|
||||
SELECT id INTO wordid FROM asearchdictionary WHERE word = s;
|
||||
raise info 'initial select found that word id is %', wordid;
|
||||
IF wordid = NULL THEN
|
||||
raise info 'since wordid was null inserting %...', wordid;
|
||||
insert into asearchdictionary (word) values(s) on conflict (word) do update set word=excluded.word returning id into wordid;
|
||||
raise info 'After insert new word returned word id %, inserting into searchkey', wordid;
|
||||
insert into asearchkey (wordid,objectid,objecttype) values(wordid,ayobjectid,ayobjecttype);
|
||||
ELSE
|
||||
raise info 'since we have initial word id from select inserting into search key the Word id %', wordid;
|
||||
insert into asearchkey (wordid,objectid,objecttype) values(wordid,ayobjectid,ayobjecttype);
|
||||
END IF;
|
||||
END LOOP;
|
||||
END;
|
||||
$BODY$;
|
||||
|
||||
Reference in New Issue
Block a user