Sql 在Postgres的GIN索引中使用少量分析器

Sql 在Postgres的GIN索引中使用少量分析器,sql,postgresql,full-text-search,Sql,Postgresql,Full Text Search,我想为Postges全文搜索创建GIN索引,我想问,如果我将表中每一行的analyzer名称存储在名为lang的单独列中,是否可以使用它为从该字段获取的每一行创建具有不同analyzer的GIN索引lang 这就是我现在用的。Analyzer–“english”,它对于索引表中的每一行都是通用的 CREATE INDEX CONCURRENTLY IF NOT EXISTS decription_fts_gin_idx ON api_product USING GIN(to_tsvector

我想为Postges全文搜索创建GIN索引,我想问,如果我将表中每一行的analyzer名称存储在名为
lang
的单独列中,是否可以使用它为从该字段获取的每一行创建具有不同analyzer的GIN索引
lang

这就是我现在用的。Analyzer–“
english
”,它对于索引表中的每一行都是通用的

CREATE INDEX CONCURRENTLY IF NOT EXISTS 
decription_fts_gin_idx ON api_product 
USING GIN(to_tsvector('english', description))
我想这样做:

CREATE INDEX CONCURRENTLY IF NOT EXISTS 
decription_fts_gin_idx ON api_product 
USING GIN(to_tsvector(api_product.lang, description))
(它不起作用)

为了从字段
lang
检索分析仪配置,并使用其名称填充索引

是否有可能以某种方式这样做,或者只可能对整个索引使用一个分析器

DDL,以防万一

-- auto-generated definition
create table api_product
(
    id                       serial       not null
        constraint api_product_pkey
            primary key,
    name                     varchar(100) not null,
    standard                 varchar(40)  not null,
    weight                   integer      not null
        constraint api_product_weight_check
            check (weight >= 0),
    dimensions               varchar(30)  not null,
    description              text         not null,
    textsearchable_index_col tsvector,
    department               varchar(30)  not null,
    lang                     varchar(25)  not null
);

alter table api_product
    owner to postgres;

create index textsearch_idx
    on api_product (textsearchable_index_col);
要为seach运行的查询:


                SELECT *,
                ts_rank_cd(to_tsvector('english', description),
                to_tsquery('english', %(keyword)s), 32) as rnk 
                FROM api_product 
                WHERE to_tsvector('english', description) @@ to_tsquery('english', %(keyword)s)
                ORDER BY rnk DESC, id 


其中“english”将更改为“
lang
”字段分析器名称(英语、法语等)

如果您提前知道要查询的语言,可以创建一系列部分索引:

CREATE INDEX CONCURRENTLY ON api_product 
USING GIN(to_tsvector('english', description)) where lang='english';
然后在查询中添加您正在搜索的语言:

 SELECT *,
            ts_rank_cd(to_tsvector('english', description),
            to_tsquery('english', %(keyword)s), 32) as rnk 
            FROM api_product 
            WHERE to_tsvector('english', description) @@ to_tsquery('english', %(keyword)s)
            and lang='english'
            ORDER BY rnk DESC, id 

您询问的内容肯定是可能的,但您的lang列类型错误:

create table api_product(description text, lang regconfig);
create index on api_product using gin (to_tsvector(lang, description));
insert into api_product VALUES ('the description', 'english');

如果你能创建你想要的索引,你会如何使用它?你希望运行什么查询?@jjanes在主文本中添加了关于你问题的答案谢谢你的回答。