oracle全文检索Word下载.docx
- 文档编号:16650783
- 上传时间:2022-11-25
- 格式:DOCX
- 页数:17
- 大小:38.86KB
oracle全文检索Word下载.docx
《oracle全文检索Word下载.docx》由会员分享,可在线阅读,更多相关《oracle全文检索Word下载.docx(17页珍藏版)》请在冰豆网上搜索。
(1).oracletext9i之前,OracleText不是默认安装的,必须手工安装。
检查数据库中是否有ctxsys用户和ctxapp脚色,如果没有这个用户和角色,这意味着你在创建数据库时没有安装oracletext功能,需要先配置上该功能。
9i安装text--创建表空间SQL>
createtablespacedrsysdatafile'
/opt/oracle10g/oradata/10gtest/drsys01.dbf'
size100m;
SQL>
connect/assysdba--创建ctxsys用户SQL>
@?
/ctx/admin/dr0csyspassworddefault_tablespace_nametemporary_tablespace_nameSQL>
connectctxsys/password--创建数据字典SQL>
/ctx/admin/dr0inst@?
/ctx/lib/libctxx9.soSQL>
/ctx/admin/defaults/drdefus.sql;
Oracl0g安装text:
connect/assysdbaSQL>
/ctx/admin/catctx.sqlctxsysTBS_DRSYStempunlockConnctxsys/ctxsysSQL>
/ctx/admin/defaults/drdefel.sql
(2).oratextAlteruserctxsysidentifiedbyctxsysaccountunlock(10g默认安装,帐号被锁定);
Createtablespaceoratextdatafile'
/opt/oracle10g/oradata/10gtest/oratext01.dbf'
size2000m;
Createuseroratextidentifiedbyoratectdefaulttablespaceoratexttemporarytablespacetemp;
Alterdatabasetempfile'
/opt/oracle10g/oradata/10gtest/temp01.dbf'
resize2000m;
Createuseroratextidentifiedbyoratextdefaulttablespaceoratexttemporarytablespacetemp;
Grantresource,connect,ctxapptooratext;
Grantexecuteonctxsys.ctx_clstooratext;
Grantexecuteonctxsys.ctx_ddltooratext;
Grantexecuteonctxsys.ctx_doctooratext;
Grantexecuteonctxsys.ctx_outputtooratext;
Grantexecuteonctxsys.ctx_querytooratext;
Grantexecuteonctxsys.ctx_reporttooratext;
Grantexecuteonctxsys.ctx_thestooratext;
Grantexecuteonctxsys.ctx_ulexertooratext;
查看系统默认的oracletext参数Selectpre_name,pre_objectfromctx_preferences(3).OracleTextOracletext索引将文本中所有的字符转化成记号(token),如会转化成www,taobao,com这样的记号。
Oracle10g里面支持四种类型的索引,context,ctxcat,ctxrule,ctxxpath索引类型描述查询操作符CONTEXT用于对含有大量连续文本数据进行检索。
支持word、html、xml、text等很多数据格式。
支持范围(range)分区,支持并行创建索引(Parallelindexing)的索引类型。
支持类型:
VARCHAR2,CLOB,BLOB,CHAR,BFILE,XMLType,andURIType.DML操作后,需要CTX_DDL.SYNC_INDEX手工同步索引如果有查询包含多个词语,直接用空格隔开(如oracleitpub)CONTAINSCTXCAT适用于混合查询语句(如查询条件包括产品id,价格,描述等)。
适合于查询较小的具有一定结构的文本段。
具有事务性。
DML操作后,索引会自动进行同步。
操作符:
and,or,>
<
=,between,inCATSEARCHCTXRULEUseCTXRULEindextobuildadocumentclassificationorroutingapplication.TheCTXRULEindexisanindexcreatedonatableofqueries,wherethequeriesdefinetheclassificationorroutingcriteria.MATCHESCTXXPATHCreatethisindexwhenyouneedtospeedupexistsNode()queriesonanXMLTypecolumn.1.ContextOracletext索引把全部的word转化成记号,context索引的架构是反向索引(invertedindex),每个记号都映射着包含它自己的文本位置,如单词dog可能会有如下的条目DogDoc1Doc3Doc5这表示dog在文档doc1,doc3,doc5中都出现过。
索引建好之后,系统中会自动产生如下DR$MYINDEX$I,DR$MYINDEX$K,DR$MYINDEX$R,DR$MYINDEX$X,MYTABLE5个表(假设表为mytable,索引为myindx)。
Dml操作后,context索引不会自动同步,需要利用ctx_ddl.sync_index手工同步索引。
例子:
Createtabledocs(idnumberprimarykey,textvarchar2(200));
Insertintodocsvalues(1,'
<
html>
californiaisastateintheus.<
/html>
'
);
Insertintodocsvalues(2,'
parisisacityinfrance.<
Insertintodocsvalues(3,'
franceisineurope.<
Commit;
/--建立context索引Createindexidx_docsondocs(text)indextypeisctxsys.contextparameters('
filterctxsys.null_filtersectiongroupctxsys.html_section_group'
--查询Columntextformata40;
Selectid,textfromdocswherecontains(text,'
france'
)>
0;
idtext-----------------------------------------3<
2<
--继续插入数据Insertintodocsvalues(4,'
losangelesisacityincalifornia.<
Insertintodocsvalues(5,'
mexicocityisbig.<
commit;
city'
--新插入的数据没有查询到idtext--------------------------------------------2<
--索引同步beginctx_ddl.sync_index('
idx_docs'
'
2m'
end;
--查询Columntextformata50;
--查到数据idtext-----------------------------------------------5<
4<
--or操作符
Selectid,textfromdocswherecontains(text,'
cityorstate'
--and操作符Selectid,textfromdocswherecontains(text,'
cityandstate'
或是Selectid,textfromdocswherecontains(text,'
citystate'
--score表示得分,分值越高,表示查到的数据越精确SELECTSCORE
(1),id,textFROMdocsWHERECONTAINS(text,'
oracle'
1)>
Context类型的索引不会自动同步,这需要在进行Dml后,需要手工同步索引。
与context索引相对于的查询操作符为contains语法:
Contains([schema.]column,text_queryvarchar2[,labelnumber])Returnnumber;
indextypeisctxsys.context:
表示所定义的索引类型为context2.Ctxcat用在多列混合查询中Ctxcat可以利用indexset建立一个索引集,把一些经常与ctxcat查询组合使用的查询列添加到索引集中。
比如你在查询一个商品名时,还需要查询生产日期,价格,描述等,你可可以将这些列添加到索引集中。
oracle将这些查询封装到catsearch操作中,从而提高全文索引的效率。
在一些实时性要求较高的交易上,context的索引不能自动同步显然是个问题,ctxcat则会自动同步索引(原文:
ThisexamplecreatesacatalogindexforanauctionsitethatsellselectronicequipmentsuchascamerasandCDplayers.Newinventoryisaddedeverydayanditemdescriptions,biddates,andpricesmustbestoredtogether.Theapplicationrequiresgoodresponsetimeformixedqueries.ThekeyistodeterminewhatcolumnsusersfrequentlysearchsothatwecancreateasuitableCTXCATindex.QueriesonthistypeofindexareissuedwiththeCATSEARCHoperator.)例子:
Createtableauction(Item_idnumber,Titlevarchar2(100),Category_idnumber,Pricenumber,Bid_closedate);
Insertintoauctionvalues(1,'
nikoncamera'
1,400,'
24-oct-2002'
Insertintoauctionvalues(2,'
olympuscamera'
1,300,'
25-oct-2002'
Insertintoauctionvalues(3,'
pentaxcamera'
1,200,'
26-oct-2002'
Insertintoauctionvalues(4,'
canoncamera'
1,250,'
27-oct-2002'
/--确定你的查询条件(很重要)Determinethatallqueriessearchthetitlecolumnforitemdescriptions--建立索引集beginctx_ddl.create_index_set('
auction_iset'
ctx_ddl.add_index('
'
price'
/*sub-indexa*/end;
--建立索引Createindexauction_titlexonauction(title)indextypeisctxsys.ctxcatparameters('
indexsetauction_iset'
Columntitleformata40;
Selecttitle,pricefromauctionwherecatsearch(title,'
camera'
orderbyprice'
)>
Titleprice-------------------------Pentaxcamera200Canoncamera250Olympuscamera300Nikoncamera400Insertintoauctionvalues(5,'
aigocamera'
1,10,'
Insertintoauctionvalues(6,'
lencamera'
1,23,'
/--测试索引是否自动同步Selecttitle,pricefromauctionwherecatsearch(title,'
price<
=100'
0;
Titleprice-------------------------aigocamera10lencamera23添加多个子查询到索引集:
begin
ctx_ddl.drop_index_set('
ctx_ddl.create_index_set('
/*sub-indexA*/ctx_ddl.add_index('
price,bid_close'
/*sub-indexB*/end;
dropindexauction_titlex;
Createindexauction_titlexonauction(title)indextypeisctxsys.ctxcatparameters('
SELECT*FROMauctionWHERECATSEARCH(title,'
price=200orderbybid_close'
orderbyprice,bid_close'
任何的Dml操作后,Ctxcat的索引会自动进行同步,不需要手工去执行,与ctxcat索引相对应的查询操作符是catsearch.语法:
Catsearch([schema.]column,Text_queryvarchar2,Structured_queryvarchar2,Returnnumber;
例子:
catsearch(text,'
dog'
foo>
15'
)catsearch(text,'
bar='
SMITH'
foobetween1and15'
foo=1andabc=123'
)3.CtxruleThefunctionofaclassificationapplicationistoperformsomeactionbasedondocumentcontent.Theseactionscanincludeassigningacategoryidtoadocumentorsendingthedocumenttoauser.Theresultisclassificationofadocument.
Createtablequeries(query_idnumber,query_stringvarchar2(80));
insertintoqueriesvalues(1,'
insertintoqueriesvalues(2,'
larryorellison'
insertintoqueriesvalues(3,'
oracleandtext'
insertintoqueriesvalues(4,'
marketshare'
--建立索引Createindexqueryxonqueries(query_string)indextypeisctxsys.ctxrule;
Columnquery_stringformata35;
Selectquery_id,query_stringfromquerieswherematches(query_string,'
oracleannouncedthatitsmarketshareindatabasesincreasedoverthelastyear.'
query_idquery_string---------------------------------------------1oracle4marketshare4.CtxxpathCreatethisindexwhenyouneedtospeedupexistsNode()queriesonanXMLTypecolumn以上是oracletext索引的几种类型,通常用的比较多的是context和ctxcat索引。
语法参考:
接下来,我们来重新看一下索引的内部处理流程,先从Datasotre开始Datastore从哪儿得到数据Filter数据如何转化成文本Lexer正在索引什么语言Wordlist如何展开词根和模糊查询Storage索引怎么存储StopList哪些词和主题不被索引SectionGroup允许分区查询吗,如何定义文档区段(4).Datastore属性数据检索负责将数据从数据存储(例如web页面、数据库大型对象或本地文件系统)中取出,然后作为数据流传送到下一个阶段。
Datastore包含的类型有Directdatastore,Multi_column_datastore,Detail_datastore,File_datastore,Url_datastore,User_datastore,Nested_datastore。
DIRECT_DATASTORE检索表(数据存储在单列中)MULTI_COLUMN_DATASTORE检索表(数据存储在多列中)DETAIL_DATASTOREDataisstoredinternallyinthetextcolumn.Document
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- oracle 全文 检索
![提示](https://static.bdocx.com/images/bang_tan.gif)