0
点赞
收藏
分享

微信扫一扫

GBase 8c附加功能之解析器

elvinyang 2022-04-27 阅读 35
数据库

文本搜索解析器负责将原文档文本分解为多个记号,并标识每个记号的类型。这里的类型集由解析器本身定义。注意,解析器并不修改文本,它只是确定合理的单词边界。由于这一限制,人们更需要定制词典,而不是为每个应用程序定制解析器。当前GBase 8c提供了一种内置解析器pg_catalog.default,能识别23中记号类型,如下表所示:

别名

描述

例子

asciiword

单词,所有 ASCII 字母

elephant

word

单词,所有字母

mañana

numword

单词,字母和数字

beta1

asciihword

带连字符的单词,所有 ASCII

up-to-date

hword

带连字符的单词,所有字母

lógico-matemática

numhword

带连字符的单词,字母和数字

postgresql-beta1

hword_asciipart

带连字符的单词部分,所有 ASCII

postgresql in the context postgresql-beta1

hword_part

带连字符的单词部分,所有字母

lógico or matemática in the context lógico-matemática

hword_numpart

带连字符的单词部分,字母和数字

beta1 in the context postgresql-beta1

email

Email 地址

foo@example.com

protocol

协议头部

http://

url

URL

example.com/stuff/index.html

host

主机

example.com

url_path

URL 路径

/stuff/index.html, in the context of a URL

file

文件或路径名

/usr/local/foo.txt, if not within a URL

sfloat

科学记数法

-1.234e56

float

十进制记数法

-1.234

int

有符号整数

-1234

uint

无符号整数

1234

version

版本号

8.3.0

tag

XML 标签

<a href="dictionaries.html">

entity

XML 实体

&

blank

空格符号

(其他不识别的任意空白或标点符号)

注意:对于解析器来说,一个“字母”的概念是由数据库的语言区域设置,即lc_ctype设置决定的。只包含基本ASCII字母的词被报告为一个单独的token类型,因为这类词有时需要被区分出来。大多数欧洲语言中,对token类型word和asciiword的处理方法是类似的。

email不支持某些由RFC 5322定义的有效电子邮件字符。具体来说,可用于email用户名的非字母数字字符仅包含句号、破折号和下划线。

解析器可能对同一内容进行重叠记号。例如,包含连字符的单词将作为一个整体进行报告,其组件也会分别被报告:

gbase=# SELECT alias, description, token FROM ts_debug('foo-bar-beta1');

      alias      |               description                |     token

-----------------+------------------------------------------+---------------

 numhword        | Hyphenated word, letters and digits      | foo-bar-beta1

 hword_asciipart | Hyphenated word part, all ASCII          | foo

 blank           | Space symbols                            | -

 hword_asciipart | Hyphenated word part, all ASCII          | bar

 blank           | Space symbols                            | -

 hword_numpart   | Hyphenated word part, letters and digits | beta1

(6 rows)

这种行为是有必要的,因为它支持搜索整个复合词和各组件。这里是另一个例子:

gbase=# SELECT alias, description, token FROM ts_debug('http://example.com/stuff/index.html');

  alias   |  description  |            token

----------+---------------+------------------------------

 protocol | Protocol head | http://

 url      | URL           | example.com/stuff/index.html

 host     | Host          | example.com

 url_path | URL path      | /stuff/index.html

(4 rows)

举报

相关推荐

0 条评论