SQL Server 2005 全文检索
首先确认安装了全文检索组件和服务,主要是Express版本,它默认是不安装的,企业版和开发版默认是安装的
1、允许数据库使用全文索引,
在SQL Server Management Studio中选择要操作的数据库的右键菜单中的属性,在属性窗口中的Files页面,有Use full-text indexing,勾选这个复选框就可以了。
2、创建full-text catalog
create fulltext catalog catalogname
运行完此命令,会在sql的安装目录下产生一个缓存文件夹:
3、创建唯一索引,对要进行全文检索的表主键创建唯一索引
create unique index indexname on talbename(columnname)
4、创建全文索引
根据之前的full-text catalog和unique index在同一表上创建全文索引
create fulltext index on tablename(column1,colunmn2,)
key index indexname on catalogname
with change_tracking auto
key index indexname on catalogname
with change_tracking auto
5、使用全文检索函数contains,
完成上面的一系列工作后,就可以在查询中使用全文索引函数contains
where contains(column, '"a" and "b" not "c"')
where contains(column, '"abc"')
where contains(column, '"a" and "b" and "c"')
where contains(column, '"a" near "b"')
where contains(column, 'formsof(inflectional, "happy")')
matches "happy", "happier", "happiest", "happily".
contains(column, 'isabout("computer" weight(0.5), "software" weight(2.0),
"development" weight(10.0)) rankmethod inner product')
where contains(column, '"abc"')
where contains(column, '"a" and "b" and "c"')
where contains(column, '"a" near "b"')
where contains(column, 'formsof(inflectional, "happy")')
matches "happy", "happier", "happiest", "happily".
contains(column, 'isabout("computer" weight(0.5), "software" weight(2.0),
"development" weight(10.0)) rankmethod inner product')