# 12.5.解析器

文本搜索解析器负责将原始文档文本拆分为代币以及识别每个令牌的类型,其中可能的类型集由解析器本身定义。请注意,解析器根本不修改文本——它只是识别看似合理的单词边界。由于范围有限,与自定义词典相比,对特定于应用程序的自定义解析器的需求更少。目前,PostgreSQL只提供一个内置解析器,已被发现对广泛的应用非常有用。

内置解析器名为PGU目录。违约。它可以识别23种令牌类型,如中所示表12.1.

表12.1.默认解析器的令牌类型

别名 描述 实例
阿西沃德 Word,所有ASCII字母 大象
单词 单词,所有字母 玛尼安娜
纽姆沃德 单词、字母和数字 β1
AsciiWord 连字符单词,全部为ASCII码 最新的
霍华德 连字符单词,所有字母 逻辑数学
努姆沃德 混合词、字母和数字 postgresql-beta1
Hword ASCIIPart 混合词部分,所有ASCII 后置的在上下文中postgresql-beta1
HWORD部分 混合词部分,所有字母 逻辑的数学的在上下文中逻辑数学
Hword numpart 混合词部分,字母和数字 贝塔1在上下文中postgresql-beta1
电子邮件 电子邮件地址 foo@example.com
协议 协议头 http://
网址 统一资源定位地址 实例com/stuff/index。html
主办 主办 实例通用域名格式
url_路径 URL路径 /资料/索引。html,在URL的上下文中
文件 文件名或路径名 /usr/local/foo。txt,如果不在URL中
斯弗洛特 科学符号 -1.234e56
浮动 十进制记数法 -1.234
智力 有符号整数 -1234
无符号整型 无符号整数 1234
版本 版本号 8.3.0
标签 XML标签 <a href=“dictionaries.html”>
实体 XML实体 &amp;
blank Space symbols (any whitespace或punctuation not otherwise recognized)

# Note

The Parser's notion of a“letter”is determined by the database's local setting,specificallyLC CtypeWords containing only the basic ascii letters are reported as a separate token type,since it is some useful to distinguish them.In most European languages,token typeswordasciiword应该像对待。

电子邮件 does not support all valid email characters as defined by RFC 5322 (opens new window)Specifically,the only non-alphanumeric characters supported for email user names are period,dash,and underscore。

这是一个很好的例子。作为一个例子,一个hyphenated单词将同时作为一个完整的单词和每个组件报告:

SELECT alias, description, token FROM ts_debug('foo-bar-beta1');
      alias      |               description                |     token