PostgreSQL文本搜索(五)——词法分析器

news/2024/7/23 11:27:24

PostgreSQL文本搜索(五)——词法分析器

文本搜索词法分析器负责将原始文档文本分割成token,并确定每个token的类型,其中可能的类型集合由词法分析器本身定义。注意分析器根本不修改文本,它只是识别合理的词的边界。由于这种有限的范围,对特定应用的自定义分析器的需求比对自定义字典的需求要少。目前PostgreSQL只提供了一个内置的分析器,它已经被发现对广泛的应用很有用。

内置的分析器被命名为pg_catalog.default。它可以识别23种标记类型,如下表所示。

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字母的词被报告为一个单独的token类型,因为有时区分它们是很有用的。在大多数欧洲语言中,token类型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

http://www.niftyadmin.cn/n/1842701.html

相关文章

解决:PLS-00103: Encountered the symbol “CREATE”

文章目录问题描述问题解决问题描述 在oracle中&#xff0c;需要修改一个PACKAGE中某一个procedure的逻辑&#xff0c;修改完后&#xff0c;将 package定义和package body放在一个脚本中来执行时&#xff0c;遇到下面的错误&#xff1a; PLS-00103: Encountered the symbol “C…

PostgreSQL文本搜索(六)——词典

PostgreSQL文本搜索&#xff08;六&#xff09;——词典 词典用于消除在搜索中不应考虑的词&#xff08;停顿词&#xff09;&#xff0c;并使词规范化&#xff0c;以便同一词的不同派生形式能够匹配。一个成功规范化的词被称为lexeme&#xff08;词位、词素&#xff09;。除了…

Java命令参数列举

目录概要使用 -D使用 -X概要 在shell脚本中&#xff0c;需要写java命令运行程序&#xff0c;注意java命令的相关参数和选项。 通过在cmd中输入java就可以查看相关规范&#xff08;前提是已经配好相关环境变量&#xff09;&#xff0c;如下&#xff1a; C:\Users\Administrato…

PostgreSQL文本搜索(七)——自定义配置

PostgreSQL文本搜索&#xff08;七&#xff09;——自定义配置 文本搜索配置指定了将文档转化为tsvector所需的所有选项&#xff1a;使用词法分析器将文本分解为token&#xff0c;以及使用词典将每个token转化为lexeme。每一次对to_tsvector或to_tsquery的调用都需要一个文本搜…

URL后面加不加“/“的区别

目录参考资料测试结论因为在项目中遇到点问题&#xff0c;就稍微总结了下这个知识点&#xff01;参考资料 RFC1630 URL后面加不加 "/"是有区别的&#xff01; 测试 不加"/“的URL&#xff0c;请求的时候&#xff0c;会向服务器请求2次 其中一个请求是301状态值…

PostgreSQL自定义文本检索分词规则

PostgreSQL自定义文本检索分词规则 PostgreSQL的倒排索引十分强大&#xff0c;虽然为文本检索设计&#xff0c;但也可以移植到其他用途。 有如下数据表&#xff0c;其中tagset是一系列tag的集合&#xff1a; idtagset1001“tag_01 tag_02 tag_05”1024“tag_02 tag_04 tag_0…

csblog: 一站式秃头孵化基地

csblog: 一站式秃头孵化基地 学习计算机过程中&#xff0c;有很多高质量博客&#xff0c;但资源分散&#xff0c;许多资源不被人所知&#xff0c;经常漫无目全网查找。 csblog网站是对全网优质计算机相关资源的整理&#xff0c;可以让初学者少走弯路。 只需要知道这个网站&a…

git高级特性之 - cherry-pick

文章目录背景介绍配置项-e&#xff0c;--edit-n&#xff0c;--no-commit-x-s&#xff0c;--signoff-m parent-number&#xff0c;--mainline parent-number实践案例自动提交不自动提交增加额外说明信息重新编辑提交信息有冲突的情况cherry-pick分支一次pick连续的多个提交转移到…