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. 一文了解 Nebula Graph DBaaS 服务——Nebula Graph Cloud Service

    Nebula Graph DBaaS 作为一款 DBaaS(DataBase as s Service)的产品,Nebula Graph Cloud Service 极大地降低了研发人员使用 Nebu ...

  2. [manjaro linux] 安装完成之后的配置工作,以及常用软件的安装

    emmm 很久没有更新了,绝对不是丢掉了博客帐号,有时间还是要好好装饰以下博客的... https://zhuanlan.zhihu.com/p/114296129 看到很多过程 sudo pacma ...

  3. 文心一言 VS 讯飞星火 VS chatgpt (207)-- 算法导论15.4 4题

    四.说明如何只使用表 c 中 2*min(m,n) 个表项及O(1)的额外空间来计算LCS的长度.然后说明如何只用 min(m,n) 个表项及O(1)的额外空间完成相同的工作.要写代码的时候,请用go ...

  4. 为什么带NOLOCK的查询语句还会造成阻塞

    背景 客户反映HIS数据库在11点出现了长时间的阻塞,直到手动KILL掉阻塞的源头.请我们协助分析原因,最终定位到.NET程序中使用的SqlDataReader未正常关闭导致. 现象 登录SQL专家云 ...

  5. C++socket服务器与客户端简单通信流程

    服务器和客户端简单通信的流程,做一个简单的复习: 1.服务器创建的流程 代码如下,各个重要函数已经写注释: #include <iostream> // 推荐加上宏定义 #define W ...

  6. CTF中常见编码

    ASCII编码 ASCII HEX DEC flag{hello_ctfer} 66 6c 61 67 7b 68 65 6c 6c 6f 5f 63 74 66 65 72 7d 102 108 9 ...

  7. Jpackage-制作无需预装Java环境的Jar可执行程序

    JAR 包要在预装 JRE 环境的系统上执行.如果没有预先安装 JRE 环境,又想直接运行 Java 程序,该怎么办呢? 这篇文章我们会先学习如何将 Java 程序打包成一个可执行的 Java JAR ...

  8. Go语言VSCode开发环境配置

    最近学习Golang,先把开发环境配置好. 一.安装Go语言开发包 https://golang.google.cn/dl/ 按步骤安装即可,安装完成后需要设置Windows环境变量 配置好,做个测试 ...

  9. FreeRTOS教程2 任务管理

    1.准备材料 正点原子stm32f407探索者开发板V2.4 STM32CubeMX软件(Version 6.10.0) Keil µVision5 IDE(MDK-Arm) 野火DAP仿真器 XCO ...

  10. vite + vue3 打包后 本地直接运行 type="module" crossorigin 替换为defer - 多个vue文件就不好使了

    vite + vue3 打包后 本地直接运行 type="module" crossorigin 替换为defer 需求: 想打包后,双击运行,不启动服务 修改 vite.conf ...