oracle 全文检索技术

1.查看用户:
select * from dba_users WHERE username='CTXSYS';select * from dba_users WHERE username='CTXSYS';
查看角色
select * from dba_roles WHERE ROLE = 'CTXAPP'
解锁用户:
ALTER USER CTXSYS ACCOUNT UNLOCK;
角色授权:
GRANT CTXAPP TO YLFWZB;或者GRANT EXECUTE ON ctx_ddl TO YLFWZB;
2.建立索引,并设置索引参数
 
BEGIN
  CTX_DDL.CREATE_PREFERENCE('my_datastore_prefs1', 'FILE_DATASTORE');
  CTX_DDL.SET_ATTRIBUTE('my_datastore_prefs1', 'path', 'F:file');-- 数据存储(Datastore)类
  CTX_DDL.CREATE_PREFERENCE('my_lexer', 'chinese_lexer');--- 词法分析器(Lexer)类
  --  ctx_ddl.create_stoplist('my_stoplist'); -- 非索引字表(Stoplist)类
  --  ctx_ddl.add_stopword('my_stoplist','有限公司'); 
  --  ctx_ddl.add_stopword('my_stoplist','股份有限公司');
  --create index YU_TEST_INDEX on YU_TEST(name) indextype is CTXSYS.CONTEXT parameters('lexer my_lexer stoplist my_stoplist'); 
  --create index mydocs_text_index on mydocs(thefile) indextype is ctxsys.context parameters('datastore mydatastore_prefs Filter ctxsys.inso_filter Lexer my_lexer');
--ctx_ddl.drop_preference('my_datastore_prefs1');删除索引参数
END;
【权限报错处理方式:
BEGIN
ctxsys.ctx_adm.set_parameter('file_access_role', 'public');
END;】
【查看索引使用错误信息
     select * from ctxsys.ctx_user_index_errors;
4.建表,索引
create table mydocs(id number primary key,title varchar2(255),thefile varchar2(255));
 
create index mydocs_text_index on mydocs(thefile) indextype is ctxsys.context parameters('datastore my_datastore_prefs1 Filter ctxsys.inso_filter Lexer my_lexer');
--thefile必须是非中文
  INSERT INTO MYDOCS (ID, TITLE, THEFILE) VALUES (1, 'DOC1', '1.doc');
  INSERT INTO MYDOCS (ID, TITLE, THEFILE) VALUES (2, 'DOC1', '2.docx');
  INSERT INTO MYDOCS (ID, TITLE, THEFILE) VALUES (3, 'DOC1', '3.pdf');
【自动产生的表 DR$myindex$I,DR$myindex$K,DR$myindex$R,DR$myindex$N
5.同步索引
  begin
    ctx_ddl.sync_index('mydocs_text_index');
    ctx_ddl.optimize_index('mydocs_text_index','full');
    END;
6.测试是否成功
    select * from mydocs  where contains(thefile,'兴趣')>0;
 总结:
oracle text 大文本检索 适合的场景:应用服务器和数据库服务器在同一个服务器中。如果不是就考虑apache 的luence技术代替
参考的文章:
比较详细:
contain用法
网页检索:
进阶:
 
 
http://blog.itpub.net/271283/viewspace-1022075/
原文地址:https://www.cnblogs.com/fireman/p/3684086.html