免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1683 | 回复: 0
打印 上一主题 下一主题

Full Text Indexing SQL [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-04-14 12:36 |只看该作者 |倒序浏览

This is one of those posts that’s for me to remember (cause I always forget it) and perhaps could come in handy for you too. From time to time I need to setup Full Text Indexing (yes I know there’s lots of alternative) and I hate using the IDE if I don’t have to.
Setting Up Full Text Indexing
sp_fulltext_database 'enable' –-need to have SP3 installed
IF EXISTS (
SELECT *
   FROM sys.fulltext_catalogs
  WHERE name = N'my_catalog_name'
)
    DROP FULLTEXT CATALOG my_catalog_name
GO
CREATE FULLTEXT CATALOG my_catalog_name
GO
IF EXISTS(
    SELECT *
      FROM sys.fulltext_indexes
      JOIN sys.tables
        ON sys.tables.object_id = sys.fulltext_indexes.object_id
     WHERE sys.tables.name = 'table_name'
)
  DROP FULLTEXT INDEX ON table_name
GO
CREATE FULLTEXT INDEX ON table_name (column1,column2,column3)
    KEY INDEX PK_table_name –-this is the name of the PK, not the column
    ON table_name
    WITH CHANGE_TRACKING AUTO
GO
ALTER FULLTEXT INDEX ON table_name
    START FULL POPULATION
This will start population of the index. There’s a whole bunch of ways to query it, but the easiest is using FREETEXT and FREETEXTTABLE.
Querying
The easiest query is something like this:
    SELECT table_name.column1, table_name.column2,
       KEY_TBL.RANK
    FROM table_name INNER JOIN
       FREETEXTTABLE(table_name, search_column, 'query value') AS KEY_TBL
       ON table_name.primary_key = KEY_TBL.[KEY]
    ORDER BY Rank DESC


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/78/showart_1899941.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP