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.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;
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');
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');
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;
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/