1.用tsvector @@ tsquery和tsquery @@ tsvector完成两个基本文本匹配
–全文检索基于匹配算子@@,当一个tsvector匹配到一个tsquery时,则返回true, tsvector 和tsquery两种数据类型可以任意排序。
SELECT 'a tester and he is tester,test tester tests'::tsvector @@ 'test'::tsquery AS RESULT;
SELECT 'a tester and he is tester,test tester tests'::tsvector @@ 'tester,test'::tsquery AS RESULT;
SELECT 'test & tester'::tsquery @@ 'a tester and he is tester,test tester tests'::tsvector AS RESULT;
SELECT 'tester & tests'::tsquery @@ 'a tester and he is tester,test tester tests'::tsvector AS RESULT;

--查看所有分词器
\dF
--查看默认分词器
show default_text_search_config;

2.创建表且至少有两个字段的类型为 text类型,在创建索引前进行全文检索
create table test(id int,name text,adder text);
INSERT INTO test VALUES(1, 'Ipg_catalog,danish ,configuration for danish language','create table test(id int,name text,adder text)');
INSERT INTO test VALUES(2, 'pg_catalog,danish111 ,configuration for danish language111','create table testerer(id int,name text,adder text)');
SELECT id, name,adder FROM test WHERE to_tsvector(name) @@ to_tsquery('danish');

3.创建 GIN 索引
--为了加速文本搜索,可以创建GIN索引(指定english配置来解析和规范化字符串)
CREATE INDEX test_idx_1 ON test USING gin(to_tsvector('english', name));
\d+ test

4.清理数据
drop table test;





