PostgreSQL:是否可以手动构建 tsvector 值?

PostgreSQL: Is it possible to build tsvector value manually?

我想实现一个信息检索系统,该系统使用向量 space 模型,但具有多术语标记和自定义术语加权函数。

我正在考虑在 PostgreSQL 而不是文件系统中构建倒排索引。我读到了关于在 tsvector 列上构建这样一个索引的 GIN 索引。

我可以在不调用 to_tsvector 函数的情况下手动构建 tsvector 值,以便我可以使用自定义标记和自定义权重构建我的 "custom" 向量吗?

您可以手工制作 tsvector。但据我所知,您只能分配 4 个不同的权重,A、B、C 或 D。必须将多词标记放在单引号中,以便将它们作为一个标记放在一起。

select $$'two words':1c oneword$$::tsvector;
         tsvector         
--------------------------
 'oneword' 'two words':1C

如果它对任何人都有帮助,请在原始答案的基础上:

select $$'foo':1 'bar':2 'baz':10$$::tsvector;
         tsvector         
--------------------------
 'bar':2 'baz':10 'foo':1
(1 row)