Search indexing best version to date
This commit is contained in:
@@ -173,70 +173,6 @@ namespace AyaNova.Util
|
||||
await ExecQueryAsync("CREATE INDEX asearchkey_wordid_otype_idx ON asearchkey (wordid, objecttype);");
|
||||
|
||||
//Search indexing stored procedure
|
||||
|
||||
////v1
|
||||
// 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$;");
|
||||
|
||||
|
||||
//v2
|
||||
// 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 nothing;
|
||||
// SELECT id INTO STRICT wordid FROM asearchdictionary WHERE word = s;
|
||||
// insert into asearchkey (wordid,objectid,objecttype) values(wordid,ayobjectid,ayobjecttype);
|
||||
// END LOOP;
|
||||
// END;
|
||||
// $BODY$;");
|
||||
|
||||
//v3
|
||||
await ExecQueryAsync(@"
|
||||
CREATE OR REPLACE PROCEDURE public.aydosearchindex(
|
||||
wordlist text[],
|
||||
@@ -256,24 +192,18 @@ BEGIN
|
||||
IF ayobjecttype=0 THEN
|
||||
RAISE EXCEPTION 'Bad object type --> %', ayobjecttype;
|
||||
END IF;
|
||||
|
||||
|
||||
IF cleanfirst=true THEN
|
||||
delete from asearchkey where objectid=ayobjectid and objecttype=ayobjecttype;
|
||||
END IF;
|
||||
|
||||
FOREACH s IN ARRAY wordlist
|
||||
LOOP
|
||||
--raise info 'processing word %',s;
|
||||
SELECT id INTO wordid FROM asearchdictionary WHERE word = s;
|
||||
--raise info 'initial select found that word id is %', wordid;
|
||||
LOOP
|
||||
SELECT id INTO wordid FROM asearchdictionary WHERE word = s;
|
||||
IF wordid IS 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;
|
||||
|
||||
Reference in New Issue
Block a user