sqlserver要实现全文检索应该如何做?

解决方案 »

  1.   

    http://www.cnblogs.com/firstyi/archive/2007/04/29/732263.html
      

  2.   

    开启全文索引服务,然后选择个有主键的表去右键创建,老简单了,pia pia 的,呵呵
      

  3.   


    1、  启用全文索引:use AdventureWorks 
    exec sp_fulltext_database 'enable'2、  全文索引是存储在指定的文件系统中的,而不是SQLServer中。exec sp_fulltext_catalog 'Cat_Desc', 'create', 'f:\ft'创建全文索引的目录3、  对表创建全文索引exec sp_fulltext_table 'databaselog', 'create', 'Cat_Desc','PK_DatabaseLog_DatabaseLogID'在已有的表上根据已有的索引创建全文索引
    4、  对表中的列添加全文索引exec sp_fulltext_column 'databaselog', 'event', 'add'
    5、  表启动完全填充exec sp_fulltext_table 'databaselog', 'start_full'
    6、  执行全文检索select * from freetexttable(databaselog, event,'ALTER_TABLE');
      

  4.   

    示例:create   table   testIndex 

              id   int   identity(1,1)   primary   key, 
              nm   varchar(100)   unique   not   null, 
              sex   varchar(10) 

    create UNIQUE index UQ__testIndex__0DAF0CB0
    on 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')<>0
    begin--如果全文目录正处于填充状态,则等待30秒后再检测一次
    waitfor delay '0:0:30'
    end--全文目录填充完成后,即可使用全文目录检索
    SELECT   *   FROM   testindex   WHERE   CONTAINS(nm,   '麦蒂') /*id          nm                                                                                                 sex        
    ----------- --------------------------------------------- ------------------------------------------------ ---------- 
    5           麦蒂未伤愈中途退出训练复出时间再度成疑                                                             北京(所影响的行数为 1 行)
    */
    insert   into   testindex   
              select   '麦蒂未伤愈中途退出训练复出时间再度成疑12121','北京'  
    go
    SELECT   *   FROM   testindex   WHERE   CONTAINS(nm,   '麦蒂')
    -----No result
    /*id          nm                                                                                                 sex        
    ----------- --------------------------------------------- ------------------------------------------------ ---------- 
    5           麦蒂未伤愈中途退出训练复出时间再度成疑                                                             北京(所影响的行数为 1 行)
    */
    go--填充全文索引目录
    execute sp_fulltext_catalog 'abc','start_full'
    go
    --检查全文目录填充情况
    While fulltextcatalogproperty('abc','populateStatus')<>0
    begin--如果全文目录正处于填充状态,则等待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'
    go
    sp_fulltext_catalog   'abc','drop'  
    go  
    drop table testIndex