This commit is contained in:
@@ -16,44 +16,39 @@ https://www.postgresqltutorial.com/plpgsql-loop-statements/
|
|||||||
|
|
||||||
-- DROP PROCEDURE public.pdoindex(text[], bigint, integer, boolean);
|
-- DROP PROCEDURE public.pdoindex(text[], bigint, integer, boolean);
|
||||||
|
|
||||||
CREATE OR REPLACE PROCEDURE public.pdoindex(
|
CREATE OR REPLACE PROCEDURE public.aydosearchindex(
|
||||||
words text[],
|
wordlist text[],
|
||||||
objectid bigint,
|
ayobjectid bigint,
|
||||||
objecttype integer,
|
ayobjecttype integer)
|
||||||
isupdate boolean DEFAULT false)
|
|
||||||
LANGUAGE 'plpgsql'
|
LANGUAGE 'plpgsql'
|
||||||
|
|
||||||
AS $BODY$DECLARE
|
AS $BODY$DECLARE
|
||||||
s text;
|
s text;
|
||||||
wordid bigint;
|
wordid bigint;
|
||||||
BEGIN
|
BEGIN
|
||||||
IF objectid=0 THEN
|
IF ayobjectid=0 THEN
|
||||||
RAISE EXCEPTION 'Bad object id --> %', objectid;
|
RAISE EXCEPTION 'Bad object id --> %', ayobjectid;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
IF objecttype=0 THEN
|
IF ayobjecttype=0 THEN
|
||||||
RAISE EXCEPTION 'Bad object type --> %', objecttype;
|
RAISE EXCEPTION 'Bad object type --> %', ayobjecttype;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
|
|
||||||
|
delete from asearchkey where objectid=ayobjectid and objecttype=ayobjecttype;
|
||||||
-- insert into asearchdictionary (word) values('{0}') on conflict (word) do update set word=excluded.word returning *
|
|
||||||
-- iterate text in loop
|
FOREACH s IN ARRAY wordlist
|
||||||
FOREACH s IN ARRAY words
|
|
||||||
LOOP
|
LOOP
|
||||||
insert into asearchdictionary (word) values(s) on conflict (word) do update set word=excluded.word returning id into wordid;
|
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);
|
insert into asearchkey (wordid,objectid,objecttype) values(wordid,ayobjectid,ayobjecttype);
|
||||||
--RAISE info 'word is %', s;
|
|
||||||
--RAISE info 'word id is %', wordid;
|
|
||||||
END LOOP;
|
END LOOP;
|
||||||
END;
|
END;
|
||||||
$BODY$;
|
$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
|
todo: Search confirm indexes are actually being used
|
||||||
|
|||||||
@@ -172,6 +172,36 @@ namespace AyaNova.Util
|
|||||||
//search does a lot of hits on searchkey looking for the wordid and optionally objecttype
|
//search does a lot of hits on searchkey looking for the wordid and optionally objecttype
|
||||||
await ExecQueryAsync("CREATE INDEX asearchkey_wordid_otype_idx ON asearchkey (wordid, objecttype);");
|
await ExecQueryAsync("CREATE INDEX asearchkey_wordid_otype_idx ON asearchkey (wordid, objecttype);");
|
||||||
|
|
||||||
|
//Search indexing stored procedure
|
||||||
|
await ExecQueryAsync(@"CREATE OR REPLACE PROCEDURE public.aydosearchindex(
|
||||||
|
wordlist text[],
|
||||||
|
ayobjectid bigint,
|
||||||
|
ayobjecttype integer)
|
||||||
|
LANGUAGE 'plpgsql'
|
||||||
|
|
||||||
|
AS $BODY$DECLARE
|
||||||
|
s text;
|
||||||
|
wordid bigint;
|
||||||
|
BEGIN
|
||||||
|
IF ayobjectid=0 THEN
|
||||||
|
RAISE EXCEPTION 'Bad object id --> %', ayobjectid;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF ayobjecttype=0 THEN
|
||||||
|
RAISE EXCEPTION 'Bad object type --> %', ayobjecttype;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
|
||||||
|
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,ayobjectid,ayobjecttype);
|
||||||
|
END LOOP;
|
||||||
|
END;
|
||||||
|
$BODY$;");
|
||||||
|
|
||||||
//create translation text tables
|
//create translation text tables
|
||||||
await ExecQueryAsync("CREATE TABLE atranslation (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name varchar(255) not null, stock bool, cjkindex bool default false)");
|
await ExecQueryAsync("CREATE TABLE atranslation (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name varchar(255) not null, stock bool, cjkindex bool default false)");
|
||||||
//LOOKAT: I don't think this is doing anything:
|
//LOOKAT: I don't think this is doing anything:
|
||||||
|
|||||||
Reference in New Issue
Block a user