9.3 9.4 9.5 9.6 10 11 12 13
阿里云PostgreSQL 问题报告 纠错本页面

12.5. 解析器

文本搜索分析器负责分离原文档文本为标记并且标识每个记号的类型,这里可能的类型集由解析器本身定义。 注意一个解析器并不修改文本—它只是确定合理的单词边界。因为这个限制范围, 为特定应用定制的分析器比自定义字典需要的更少。目前PostgreSQL提供了只有一个内置的解析器, 这已被用于一个广泛的应用中。

内置分析器命名pg_catalog.default。它识别23种标记类型,显示在表 12-1中。

表 12-1. 缺省分析器的标记类型

AliasDescriptionExample
asciiwordWord, all ASCII letterselephant
wordWord, all lettersmañana
numwordWord, letters and digitsbeta1
asciihwordHyphenated word, all ASCIIup-to-date
hwordHyphenated word, all letterslógico-matemática
numhwordHyphenated word, letters and digitspostgresql-beta1
hword_asciipartHyphenated word part, all ASCIIpostgresql in the context postgresql-beta1
hword_partHyphenated word part, all letterslógico or matemática in the context lógico-matemática
hword_numpartHyphenated word part, letters and digitsbeta1 in the context postgresql-beta1
emailEmail addressfoo@example.com
protocolProtocol headhttp://
urlURLexample.com/stuff/index.html
hostHostexample.com
url_pathURL path/stuff/index.html, in the context of a URL
fileFile or path name/usr/local/foo.txt, if not within a URL
sfloatScientific notation-1.234e56
floatDecimal notation-1.234
intSigned integer-1234
uintUnsigned integer1234
versionVersion number8.3.0
tagXML tag<a href="dictionaries.html">
entityXML entity&amp;
blankSpace symbols(any whitespace or punctuation not otherwise recognized)

注意: 注意:一个"字母"的语法分析器的概念是由数据库的区域设置决定的,特别是lc_ctype。 只包含基本ASCII字母的词作为一个单独的标记类型被报告,因为区分他们有时候是有用的。 大多数欧洲语言,标记类型wordasciiword应该一视同仁。

email不支持由RFC 5322定义的所有有效的电子邮件字符。具体来说, 唯一的非字母数字字符支持电子邮件用户名有句号,破折号和下划线。

对于分析器从文本的同一块产生重叠的标记是可能的。作为一个例子, 一个连字符的单词将作为整个单词和每个组件被报道:

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

这种行为是可取的,因为它允许为整个复合词和组件进行搜索。这里是另一个很好的例子:

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

<
/BODY >