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每日一练(全文检索)的更多相关文章

  1. CSS3每日一练之内容处理-嵌套编号

    出处:http://www.w3cfuns.com/thread-5592229-1-17.html 1.大标题一   1.子标题   2.子标题   3.子标题2.大标题二   1.子标题   2. ...

  2. CSS3每日一练之选择器-结构性伪类选择器

    <!DOCTYPE HTML> <html> <head> <meta charset="gb2312"> <title> ...

  3. HTML5每日一练之progress标签的应用

    progress标签:从名字上来看,估计大家也能猜到这个标签是什么标签了,没错,他是一个进度条.在HTML5中我们终于可以不用模拟了. <progress id="W3Cfuns_pr ...

  4. HTML5每日一练之figure新标签的应用

    igure元素是一种元素的组合,可带有标题(可选).figure标签用来表示网页上一块独立的内容,将其从网页上移除后不会对网页上的其他内容产生影响.figure所表示的内容可以是图片.统计图或代码示例 ...

  5. HTML5每日一练之details展开收缩标签的应用

    details标签的出现,为我们带来了更好的用户体验,不必为这种收缩展开的效果再编写JS来实现.注:目前仅Chrome支持此标签. details有一个新增加的子标签——summary,当鼠标点击su ...

  6. 每日一小练——Eratosthenes 筛选法

    上得厅堂.下得厨房,写得代码.翻得围墙,欢迎来到睿不可挡的每日一小练! 题目:Eratosthenes筛选法 内容: 求质数是一个非常普遍的问题,通常不外乎用数去除.除到不尽时,给定的数就是质数.可是 ...

  7. 每日一小练——高速Fibonacci数算法

    上得厅堂,下得厨房,写得代码,翻得围墙,欢迎来到睿不可挡的每日一小练! 题目:高速Fibonacci数算法 内容:先说说Fibonacci数列,它的定义是数列:f1,f2....fn有例如以下规律: ...

  8. linux每日一练:Enable multithreading to use std::thread: Operation not permitted问题解决

    linux每日一练:Enable multithreading to use std::thread: Operation not permitted问题解决 在linux在需要使用c++11时会遇到 ...

  9. linux命令每日一练:find与rm实现查找并删除目录或文件

    linux命令每日一练 linux中find与rm实现查找并删除目录或文件 linux 下用find命令查找文件,rm命令删除文件. 删除指定目录下指定文件 find 要查找的目录名 -name .s ...

  10. WindowsAPI每日一练(2) 使用应用程序句柄

    WindowsAPI每日一练系列 :https://www.cnblogs.com/LexMoon/category/1246238.html WindowsAPI每日一练() WinMain Win ...

随机推荐

  1. 【Azure Spring Cloud】部署Azure spring cloud 失败

    问题描述 使用Azure CLI指令部署Azure Spring Cloud项目失败,错误消息提示没有安装"azure.storage.blob"模块 问题分析 根据错误提示,是p ...

  2. 【Azure 环境】Azure 的PaaS服务如果涉及到安全漏洞问题后,我们如何确认所用服务的实例(VM:虚拟机)的操作系统已修复该补丁呢?

    问题描述 如上图中PaaS所不可见区域, 操作系统级别的内容我们并不知道具体的内容.如果当出现新的操作系统级别的安全漏洞时候,我们如何来确认当前所使用的Azure PaaS服务所在主机的OS已经修复了 ...

  3. Educational Codeforces Round 158 (Rated for Div. 2)C. Add, Divide and Floor(思维/数学)

    C. Add, Divide and Floor 这里我们选择固定最小数不变,然后每次让其他数向最小数靠近,模拟一下可以发现,只要最大值变为和最小值一样,其他都会和最小值一样. #include &l ...

  4. H3C-IP路由器

    定义 路由器负责将数据报文在IP网段之间进行转发 路由器负责将数据报文在IP网段之间进行转发 路由是指导路由器如何进行数据转发的路径信息 作用 路由器负责将数据报文在逻辑网段间进行转发 路由器是指导路 ...

  5. pip 安装requirements.txt 的问题

    用新环境 在进行pip 安装的时候, 如果出现不进行安装 ,但是不报错就是满足条件,这个时候重新起一个shell,然后进行pip的安装.

  6. ypipe, zmq的核心部件,无锁读写的管道。

    必须指出,无锁读写只限于单个读跟单个写之间,读与读,还有写与写之间必须确保同步.所以ypipe不必读写锁rwlock或者读写之间的锁,但需要读锁跟写锁两个锁,在读端之间或在写端之间仍然是临界资源.本质 ...

  7. Oss流程分析

    最新式上传方案是:前端上传获取token,然后token中带有bucket.账号.回调地址等相关信息,前端直接上传到阿里云,阿里云上传成功后回调之前设定好的地址,完成上传.(下图是技术负责人的图,盗来 ...

  8. FTP的配置和管理

    实验环境: 两台windows servers 一台已经配置了FTP服务器,IP为192.168.1.220,vmnet1 一台作为客户端测试,IP为192.168.1.138,vmnet1 一:FT ...

  9. C++ Qt开发:QProcess进程管理模块

    Qt 是一个跨平台C++图形界面开发库,利用Qt可以快速开发跨平台窗体应用程序,在Qt中我们可以通过拖拽的方式将不同组件放到指定的位置,实现图形化开发极大的方便了开发效率,本章将重点介绍如何运用QPr ...

  10. Oracle 获取月初、月末时间,获取上一月月初、月末时间

    select trunc(sysdate, 'mm'), last_day(trunc(sysdate)), trunc(add_months(trunc(sysdate), -1), 'mm'), ...