amutu / zhparser

zhparser is a PostgreSQL extension for full-text search of Chinese language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

text search configuration name "zhparser" must be schema-qualified

hegphegp opened this issue · comments

commented

创建触发器,但是插入语句跑错了

  • text search configuration name "zhparser" must be schema-qualified
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE EXTENSION IF NOT EXISTS zhparser;
CREATE TEXT SEARCH CONFIGURATION zhparser (PARSER = zhparser);
ALTER TEXT SEARCH CONFIGURATION zhparser ADD MAPPING FOR n,v,a,i,e,l WITH simple;
CREATE TABLE new_table (
    id varchar(32) primary key,
    title varchar(50) not null,
    content text not null,
    title_content_full_text tsvector  -- 新建一列,存储to_tsvector函数的内容,再对该列建gin索引
);
CREATE INDEX new_table_title_content_filed_full_text_index ON new_table USING gin(title_content_full_text);
-- 创建触发器,每次更新数据时自动更新索引
CREATE TRIGGER new_table_title_content_full_text_index_trigger BEFORE INSERT OR UPDATE ON new_table FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger(title_content_full_text, 'zhparser', title);
INSERT INTO "public"."new_table"("id", "title", "content") VALUES ('1', '搜索', '内容');

commented

我知道原因了,创建触发器时用到的tsvector_update_trigger函数的第2个参数,必须写zhparser所在的schema,即public.zhparser

CREATE TRIGGER new_table_title_content_full_text_index_trigger BEFORE INSERT OR UPDATE ON new_table FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger(title_content_full_text, 'public.zhparser', title);