全文检索

来源:互联网 发布:长沙seo公司 编辑:程序博客网 时间:2024/04/26 22:23

关于全文检索的说明很多了,现写一个完整的例子!!Create Table testIndex (           id   int   identity(1,1)   primary   key,           nm   varchar(100)   unique   not   null,           sex   varchar(10) ) create UNIQUE index UQ__testIndex__0DAF0CB0on testindex(nm)insert   into   testindex             select   'aaabbb','m'   union   all           select   'bbb','w'   union   all           select   'ccc','w'   union   all           select   'ddd','m' 准备一组汉字记录insert   into   testindex             select   '麦蒂未伤愈中途退出训练复出时间再度成疑','北京'  go--创建全文目录 sp_fulltext_catalog   'abc','create'     go--创建全文索引(‘表名‘,’创建/删除‘,’全文目录名‘,’约束名‘) sp_fulltext_table   'testindex','create','abc','UQ__testIndex__0DAF0CB0' go--添加列到全文索引(‘表名‘,’列名‘,’添加/删除‘) sp_fulltext_column   'testindex','nm','add' go--建立全文索引--activate,是激活表的全文检索能力,也就是在全文目录中注册该表execute sp_fulltext_table 'testindex','activate'go--填充全文索引目录execute sp_fulltext_catalog 'abc','start_full'go --检查全文目录填充情况While fulltextcatalogproperty('abc','populateStatus')<>0begin--如果全文目录正处于填充状态,则等待30秒后再检测一次waitfor delay '0:0:30'end --全文目录填充完成后,即可使用全文目录检索 SELECT   *   FROM   testindex   WHERE   CONTAINS(nm,   '麦蒂') /**//*id          nm                                                                                                 sex        ----------- --------------------------------------------- ------------------------------------------------ ---------- 5           麦蒂未伤愈中途退出训练复出时间再度成疑                                                             北京(所影响的行数为 1 行)*/ 再次插入新的数据, insert   into   testindex             select   '麦蒂未伤愈中途退出训练复出时间再度成疑12121','北京'  goSELECT   *   FROM   testindex   WHERE   CONTAINS(nm,   '麦蒂')-----这个时候进行select实际上得不到理想的结果,还是老数据,没有增加的这一条/**//*id          nm                                                                                                 sex        ----------- --------------------------------------------- ------------------------------------------------ ---------- 5           麦蒂未伤愈中途退出训练复出时间再度成疑                                                             北京(所影响的行数为 1 行)*/go --填充全文索引目录execute sp_fulltext_catalog 'abc','start_full'go --检查全文目录填充情况While fulltextcatalogproperty('abc','populateStatus')<>0begin--如果全文目录正处于填充状态,则等待30秒后再检测一次waitfor delay '0:0:30'end --重新填充后就会有想要的结果 了SELECT   *   FROM   testindex   WHERE   CONTAINS(nm,   '麦蒂')go/**//*id          nm                                                                                                   sex        ----------- ---------------------------------------------------------------------------------------------------- ---------- 6           麦蒂未伤愈中途退出训练复出时间再度成疑12121                                                                             北京5           麦蒂未伤愈中途退出训练复出时间再度成疑                                                                                  北京(所影响的行数为 2 行)*/--清理现场 sp_fulltext_table  'testindex','drop'gosp_fulltext_catalog   'abc','drop'  go  drop table testIndex

来源:http://topic.csdn.net/u/20080620/15/f4bcea55-7822-4b68-b618-8688dc06bd84.html?seed=1603777612

原创粉丝点击