返回首页

gbase数据、南大通用产品文档:GBase8a|

更新日期:2024年09月11日

+-------+-----------------------------------+
2 rows in set


GBase 8c 管理员指南
南大通用数据技术股份有限公司
1
1
数据库管理
数据库管理员可以通过gha_ctl 工具
(详见
《GBase 8c V5_3.0.0 工具参考手册》
中gha_ctl
章节),对GBase 8c 数据库进行启动、停止等操作。

tsvector 类型表示一个检索单元,通常是一个数据库表中一行的文本字段或者这些字段
的组合。to_tsvector 函数通常用于解析和标准化文档字符串。
tsvector 类型的值是一个唯一标准词位的有序列表。把同一个词的变型体都进行标准化
得到同样的标准词,在输入的同时,tsvector 会自动排序和消除重复。例如:
gbase=# SELECT 'a fat cat sat on a mat and ate a fat rat'::tsvector;
tsvector
----------------------------------------------------
'a' 'and' 'ate' 'cat' 'fat' 'mat' 'on' 'rat' 'sat'
(1 row)
从上面的例子可以看出,tsvector 格式中,字符串按照空格进行分词,并按照长短和字
母排序。但是如果词条中需要包含空格或标点符号,可以用引号标记。例如:
gbase=# SELECT $$the lexeme ' ' contains spaces$$::tsvector;
tsvector
----------------------------------------
' ' 'contains' 'lexeme' 'spaces' 'the'
(1 row)
如果在词条中使用引号,可以使用双$$符号作为标记。例如:
gbase=# SELECT $$the lexeme 'Joe''s' contains a quote$$::tsvector;
tsvector
------------------------------------------------
'Joe''s' 'a' 'contains' 'lexeme' 'quote' 'the'
(1 row)
词条位置常量也可以放到词汇中:

GBase 8c SQL 参考手册
南大通用数据技术股份有限公司
71
gbase=# SELECT 'a:1 fat:2 cat:3 sat:4 on:5 a:6 mat:7 and:8 ate:9 a:10 fat:11
rat:12'::tsvector;
tsvector
-----------------------------------------------------------------------------
--
'a':1,6,10 'and':8 'ate':9 'cat':3 'fat':2,11 'mat':7 'on':5 'rat':12 'sat':4
(1 row)
位置常量通常表示文档中源字的位置,可以用于排名。位置常量的范围是1 到16383,
最大值默认是16383。相同词的重复位会被忽略掉。
拥有位置的词汇可以使用权标记,这个权可以是A、B、C 或D。默认为D。因此输出
中不会显示权为D:
gbase=# SELECT 'a:1A fat:2B,4C cat:5D'::tsvector;
tsvector
----------------------------
'a':1A 'cat':5 'fat':2B,4C
(1 row)
权可以用来反映文档结构,如:
标记标题与主体文字的区别。全文检索排序函数可以为
不同的权标记分配不同的优先级。
以下示例为tsvector 类型标准用法:
gbase=# SELECT 'The Fat Rats'::tsvector;
tsvector
--------------------
'Fat' 'Rats' 'The'
(1 row)
但是对于英文全文检索应用来说,以上单词会判定为非规范化的,所以需要通过
to_tsvector 函数对这些单词进行规范化处理:
gbase=# SELECT to_tsvector('english', 'The Fat Rats');
to_tsvector
-----------------
'fat':2 'rat':3
(1 row)

GBase 8c SQL 参考手册
南大通用数据技术股份有限公司
72