diff --git "a/content/zh/post/zhangcuiping/\345\246\202\344\275\225\345\257\271\345\215\225\344\270\252\345\255\227\343\200\201\350\257\215\344\273\245\345\217\212\351\225\277\345\217\245\345\255\220\350\277\233\350\241\214\346\243\200\347\264\242.md" "b/content/zh/post/zhangcuiping/\345\246\202\344\275\225\345\257\271\345\215\225\344\270\252\345\255\227\343\200\201\350\257\215\344\273\245\345\217\212\351\225\277\345\217\245\345\255\220\350\277\233\350\241\214\346\243\200\347\264\242.md" new file mode 100644 index 0000000000000000000000000000000000000000..65723a6238ee6593037237071b379e42216b996b --- /dev/null +++ "b/content/zh/post/zhangcuiping/\345\246\202\344\275\225\345\257\271\345\215\225\344\270\252\345\255\227\343\200\201\350\257\215\344\273\245\345\217\212\351\225\277\345\217\245\345\255\220\350\277\233\350\241\214\346\243\200\347\264\242.md" @@ -0,0 +1,66 @@ ++++ + +title = "如何对单个字、词以及长句子进行检索" + +date = "2023-07-21" + +tags = ["数据库入门"] + +archives = "2023-07" + +author = "张翠娉" + +summary = "如何对单个字、词以及长句子进行检索" + +img = "/zh/post/zhangcuiping/title/img.png" + +times = "15:20" + ++++ + +# 如何对单个字、词以及长句子进行检索? + +1. 创建表并插入数据。 + + ``` + Drop table if exists t_search; + + CREATE TABLE t_search (id int, title text, keyword text, abstract text, body text, ti tsvector); + + INSERT INTO t_search(id, title, keyword, abstract, body) VALUES (1, 'Northern area', 'Beijing', 'China','China, officially the People Republic of China (PRC), located in Asia, is the most populous state.'); + + INSERT INTO t_search(id, title, keyword, abstract, body) VALUES (1, 'eastern area', 'Shanghai', 'China','China, located in east of China, is an international city.'); + ``` + +2. 对单个字进行全文检索。 + + ``` + MogDB=# Select * from t_search where to_tsvector(keyword)@@ to_tsquery( 'Beijing' ); + id | title | keyword | abstract | body + | ti + ----+---------------+---------+----------+-------------------------------------------------------------------------------------- + --------------+---- + 1 | Northern area | Beijing | China | China, officially the People Republic of China (PRC), located in Asia, is the most po + pulous state. | + (1 row) + ``` + +3. 对单个词进行全文检索。 + + ``` + MogDB=# Select * from t_search where to_tsvector(title)@@ plainto_tsquery( 'eastern area' ); + id | title | keyword | abstract | body | ti + ----+--------------+----------+----------+------------------------------------------------------------+---- + 1 | eastern area | Shanghai | China | China, located in east of China, is an international city. | + (1 row) + ``` + +4. 对长句子进行全文检索。 + + ``` + MogDB=# Select * from t_search where to_tsvector(body)@@ plainto_tsquery( 'China, located in east of China, is an international city.' ); + id | title | keyword | abstract | body | ti + ----+--------------+----------+----------+------------------------------------------------------------+---- + 1 | eastern area | Shanghai | China | China, located in east of China, is an international city. | + (1 row) + ``` \ No newline at end of file