openGauss每日一练(全文检索)
openGauss 每日一练(全文检索)
本文出处:https://www.modb.pro/db/224179
学习目标
学习 openGauss 全文检索
openGauss 提供了两种数据类型用于支持全文检索。tsvector 类型表示为文本搜索优化的文件格式,tsquery 类型表示文本查询
课后作业
1.用 tsvector @@ tsquery 和 tsquery @@ tsvector 完成两个基本文本匹配
omm=# SELECT 'a fat cat sat on a mat and ate a fat rat'::tsvector @@ 'cat & rat'::tsquery AS RESULT;
result
t
(1 row)
omm=# SELECT 'fat & cow'::tsquery @@ 'a fat cat sat on a mat and ate a fat rat'::tsvector AS RESULT;
result
f
(1 row)
omm=#
2.创建表且至少有两个字段的类型为 text 类型,在创建索引前进行全文检索
omm=# CREATE SCHEMA tsearch;
CREATE TABLE tsearch.pgweb(id int, body text, title text, last_mod_date date);
CREATE SCHEMA
omm=# CREATE TABLE tsearch.pgweb(id int, body text, title text, last_mod_date date);
INSERT INTO tsearch.pgweb VALUES(1, 'China, officially the People''s Republic of China(PRC), located in Asia, is the world''s most populous state.', 'China', '2010-1-1');
CREATE TABLE
omm=# INSERT INTO tsearch.pgweb VALUES(1, 'China, officially the People''s Republic of China(PRC), located in Asia, is the world''s most populous state.', 'China', '2010-1-1');
INSERT INTO tsearch.pgweb VALUES(2, 'America is a rock band, formed in England in 1970 by multi-instrumentalists Dewey Bunnell, Dan Peek, and Gerry Beckley.', 'America', '2010-1-1');
INSERT 0 1
omm=# INSERT INTO tsearch.pgweb VALUES(2, 'America is a rock band, formed in England in 1970 by multi-instrumentalists Dewey Bunnell, Dan Peek, and Gerry Beckley.', 'America', '2010-1-1');
INSERT 0 1
omm=# INSERT INTO tsearch.pgweb VALUES(3, 'England is a country that is part of the United Kingdom. It shares land borders with Scotland to the north and Wales to the west.', 'England','2010-1-1');
INSERT 0 1
omm=#
omm=# SELECT id, body, title FROM tsearch.pgweb WHERE to_tsvector(body) @@ to_tsquery('america');
id | body | title
----+-------------------------------------------------------------------------------------------------------------------------+---------
2 | America is a rock band, formed in England in 1970 by multi-instrumentalists Dewey Bunnell, Dan Peek, and Gerry Beckley. | America
(1 row)
omm=#
3.创建 GIN 索引
omm=# CREATE INDEX pgweb_idx_1 ON tsearch.pgweb USING gin(to_tsvector('english', body));
CREATE INDEX
omm=#
4.清理数据
omm=# drop schema tsearch;
DROP SCHEMA
omm=#
openGauss每日一练(全文检索)的更多相关文章
- CSS3每日一练之内容处理-嵌套编号
出处:http://www.w3cfuns.com/thread-5592229-1-17.html 1.大标题一 1.子标题 2.子标题 3.子标题2.大标题二 1.子标题 2. ...
- CSS3每日一练之选择器-结构性伪类选择器
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312"> <title> ...
- HTML5每日一练之progress标签的应用
progress标签:从名字上来看,估计大家也能猜到这个标签是什么标签了,没错,他是一个进度条.在HTML5中我们终于可以不用模拟了. <progress id="W3Cfuns_pr ...
- HTML5每日一练之figure新标签的应用
igure元素是一种元素的组合,可带有标题(可选).figure标签用来表示网页上一块独立的内容,将其从网页上移除后不会对网页上的其他内容产生影响.figure所表示的内容可以是图片.统计图或代码示例 ...
- HTML5每日一练之details展开收缩标签的应用
details标签的出现,为我们带来了更好的用户体验,不必为这种收缩展开的效果再编写JS来实现.注:目前仅Chrome支持此标签. details有一个新增加的子标签——summary,当鼠标点击su ...
- 每日一小练——Eratosthenes 筛选法
上得厅堂.下得厨房,写得代码.翻得围墙,欢迎来到睿不可挡的每日一小练! 题目:Eratosthenes筛选法 内容: 求质数是一个非常普遍的问题,通常不外乎用数去除.除到不尽时,给定的数就是质数.可是 ...
- 每日一小练——高速Fibonacci数算法
上得厅堂,下得厨房,写得代码,翻得围墙,欢迎来到睿不可挡的每日一小练! 题目:高速Fibonacci数算法 内容:先说说Fibonacci数列,它的定义是数列:f1,f2....fn有例如以下规律: ...
- linux每日一练:Enable multithreading to use std::thread: Operation not permitted问题解决
linux每日一练:Enable multithreading to use std::thread: Operation not permitted问题解决 在linux在需要使用c++11时会遇到 ...
- linux命令每日一练:find与rm实现查找并删除目录或文件
linux命令每日一练 linux中find与rm实现查找并删除目录或文件 linux 下用find命令查找文件,rm命令删除文件. 删除指定目录下指定文件 find 要查找的目录名 -name .s ...
- WindowsAPI每日一练(2) 使用应用程序句柄
WindowsAPI每日一练系列 :https://www.cnblogs.com/LexMoon/category/1246238.html WindowsAPI每日一练() WinMain Win ...
随机推荐
- 设置 sudo 无需输入密码
* 设置 sudo 无需输入密码,如下:* [root@localhost ~]# visudo* 在"root ALL=(ALL) ALL"这一行下面,再加入一行:* 将原来的: ...
- 【Azure 事件中心】使用Kafka的性能测试工具(kafka-producer-perf-test)测试生产者发送消息到Azure Event Hub的性能
问题描述 Azure Event Hub支持 kafka,所以为了测试消息生产者所在环境与Azure Event Hub之间发送消息的性能如何,特别使用 kafka 官方测试生产者,消费者的性能工具 ...
- 【Azure Redis 缓存】Azure Cache for Redis 服务的导出RDB文件无法在自建的Redis服务中导入
问题描述 使用微软云的Redis服务,导出它的RDB文件后,想把数据恢复到本地自建的Redis服务中,发现出现如下错误: 15000:S 21 Jun 08:14:11.199 * Retrying ...
- 云原生基础设施实践:NebulaGraph 的 KubeBlocks 集成故事
像是 NebulaGraph 这类基础设施上云,通用的方法一般是将线下物理机替换成云端的虚拟资源,依托各大云服务厂商实现"服务上云".但还有一种选择,就是依托云数据基础设施,将数据 ...
- 论文《Attention is all you need》阅读笔记
Attention is all you need Transformer模型 Model Architecture Transformer结构上和传统的翻译模型相同,拥有encoder-decode ...
- [Linux] rockylinux9.1 的部署使用过程 -- ZFS 虚拟机 cockpit podman samba
备选镜像 | Rocky Linux rocky linux 使用记录 - 个人文章 - SegmentFault 思否 # https://blog.csdn.net/NeverGUM/articl ...
- Java 类的结构之三 :构造器(或构造方法,constructor)的使用
1 /* 2 * 类的结构之三 :构造器(或构造方法,constructor)的使用 3 * construct:建设 建造 4 * 5 * 一.构造器的作用: 6 * 创建对象 7 * 初始化对象的 ...
- 我的闲鱼Python爬虫接单总结和经验,最高600元一单
最近,我在闲鱼上利用 Python 爬虫技术接了一些任务,想必你一定好奇,通过这样的方式,到底能不能挣钱,能挣多少钱?今天我就来分享一下我的经验和总结. 一.接单经历 之前 Vue 的作者尤大在微博上 ...
- Educational Codeforces Round 65 (Rated for Div. 2)C. News Distribution(模拟,计算的时候去重)
这道题目明显和出现4次的数和出现2次的数的个数有关系,只需要在每次更新之后维护这两个信息即可,我们在算出现2次的数的个数时其实会把出现4次的数的个数会把出现2次的数的个数+2,在判断时需要考虑这一点. ...
- notion database 必知必会
notion database 必知必会 用过 mysql 的同学一定很容易上手 notion .在 notion 中,掌握好 database,基本上就掌握了 notion 最核心的概念. noti ...