Oracle Text 实现全文搜索

1。普通数据搜索

1.创建表  Test 并添加数据。

Create Table Test

(

id
number,

title
varchar2(30),

body
varchar2(1000)

)

2.为文本建立索引

  Oracle Text 索引有三种,

   (1)Context,应用于比大/长的文本搜索。

   (2) Ctxcat   应用于多字段的文本查询,性能比Context好,且CtxCat 索引是事务性的,直线DML后数据库会自动同步索引,不香Context要用到 Ctx_dll.sync_index 同步。

   (3) CtxRule

Create index test_ctx_idx

on test(body)

indextype
is ctxsys.context;

commit;

  索引创建成功后,表记录会被拆分成很多部分进行存储。

  注意:索引创建后,如果再往表添加数据,此记录不会被拆分存储,必须同步索引(ctx_ddl.sync_index)或重建索引(alter index ... rebuild)

 3.查询

  (1)contains 搜索

   

select id,title from test where contains(body,'福建')>0
select id,title from test where contains(body,'福建' or '广东')>0

  也可以使用 fuzzy()函数搜索,该函数运行错一个字母

  比如:

  select id,title from test where contain(body,'fuzzy("oracel")') >0

(2)About查询

2.大文本 Clob的全文检索

  这个其实差不多。

  另外,想看更详细的内容可以查看<做自己的搜索引擎> 这本书,里面的例子很简单。

  

   

原文地址:https://www.cnblogs.com/dooom/p/1841322.html