sql server 2008全文索引干扰词示例--转
处理网站查询包含”之”字出现”全文搜索条件中包含干扰词”现象的总结:
author:perfectaction
Sql server 2008全文索引的干扰词表默认在Resource库系统表内,无法更改,但sql2008提供了自定义干扰词表的功能,可绑定到某个全文索引上。
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
相关操作如下:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
--sql server 2008 全文索引建立及创建全文非索引字表(干扰词表)
--以dbtest的user_info表为例
--选择数据库
USE dbtest
GO
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
--创建全文目录,这个是逻辑名
CREATE FULLTEXT CATALOG user_info AS DEFAULT;
GO
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
--创建全文非索引字表(干扰词表)
CREATE FULLTEXT STOPLIST T_FULLTEXT_STOPLIST_user_info --全文非索引字表表名
FROM SYSTEM STOPLIST; --从系统全文非索引字表导入
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
--删除我们不需要的干扰词,如"之"字
ALTER FULLTEXT STOPLIST [T_FULLTEXT_STOPLIST_user_info]
DROP '之' LANGUAGE 'Simplified Chinese';
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
--增加我们需要的干扰词,如"之"字
ALTER FULLTEXT STOPLIST [T_FULLTEXT_STOPLIST_user_info]
ADD '之' LANGUAGE 'Simplified Chinese';
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
--创建表user_info的全文索引
CREATE FULLTEXT INDEX ON [dbo].[user_info] --表名
([mem_name] --列名
LANGUAGE [Simplified Chinese])
KEY INDEX [PK_user_info] --聚集索引名
ON (FILEGROUP [ftfg_FT_user_info]) --指定文件组名,如不指定,则存在当前表所在文件组
WITH (CHANGE_TRACKING = AUTO,
STOPLIST =T_FULLTEXT_STOPLIST_user_info --指定使用的全文非索引字表
)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
--其它:
--对已存在全文索引指定全文非索引字表,命令执行后,
--如果CHANGE_TRACKING = AUTO,则会自动修改已填充索引,但不会全部重填
ALTER FULLTEXT INDEX on user_info --表名
SET STOPLIST =SYSTEM --指定使用的全文非索引字表为系统自带
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
ALTER FULLTEXT INDEX on user_info --表名
SET STOPLIST=T_FULLTEXT_STOPLIST_user_info ;--指定使用的全文非索引字表为用户自定义
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
--启动填充,如果CHANGE_TRACKING != AUTO,则需要启动一次填充才使新设定的全文非索引字表生效;
ALTER FULLTEXT INDEX on user_info --表名
START FULL POPULATION
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
CREATE FULLTEXT STOPLIST T_FULLTEXT_STOPLIST_user_info --全文非索引字表表名
FROM SYSTEM STOPLIST;
--删除我们不需要的干扰词,如"之"字 ;英文用 language 'English' or Language_id 1033
ALTER FULLTEXT STOPLIST [T_FULLTEXT_STOPLIST_user_info]
DROP '之' LANGUAGE 'Simplified Chinese';
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
--增加我们需要的干扰词,如"之"字
ALTER FULLTEXT STOPLIST [T_FULLTEXT_STOPLIST_user_info]
ADD '之' LANGUAGE 'Simplified Chinese';
ALTER FULLTEXT INDEX on [tablename] --表名
SET STOPLIST=T_FULLTEXT_STOPLIST_user_info ;--指定使用的全文非索引字表为用户自定义
=================================================================
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
===========================================================================================
总结:
1.SQL 2008 需要开启search 服务。
2.SQL 2008 登陆角色要有相应的操作权限,一般加上SYSADMIN
3.SQL 2008 的数据库的兼容基本应该是SQL SERVER 2008(100)
4.对已存在的fulltext功能的table,或者从SQL 2005 升级到SQL 2008 的数据库;
需要做如下修改:
--创建全文非索引字表(干扰词表)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
FROM SYSTEM STOPLIST;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
--应用到指定table中
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
--查看系统默认干扰词列表
select * from sys.fulltext_stopwords
--查看table是否存在全文索引
select * from sys.fulltext_indexes
where object_id = object_id('[tablename]')
在SQL 2008中,我们可以通过查询系统表值函数sys.dm_fts_index_keywords 和sys.dm_fts_index_keywords_by_document来查看断词结果。
SELECT display_term FROM sys.dm_fts_index_keywords_by_document(DB_ID('TestFT'),OBJECT_ID('TB')) WHERE document_id=2and column_id =3--全文键值为2 第3列
使用sys.dm_fts_parser来分析断词结果,sys.dm_fts_parser函数用起来更加灵活。
SELECT special_term,display_term FROM sys.dm_fts_parser('宁夏固原有一位网友给敬爱的苍老师写了一封信',1028,0,0) --繁体中文
SELECT special_term,display_term FROM sys.dm_fts_parser('宁夏固原有一位网友给敬爱的苍老师写了一封信',2052,0,0) --简体中文
=================================================================
The first thing you need to do is set the compatibility level up to 2008:
ALTERDATABASE[MyDatabase]SET COMPATIBILITY_LEVEL =100
Then, when creating the full-text index through the wizard, there is a step that allows you to ignore stopwords for the index
edit: Here's the script to do it as well:
ALTER FULLTEXT INDEXON MyTable SET STOPLIST =OFF
==============================================================
使用 transform noise words 服务器配置选项可以取消干扰词(即非索引字)导致全文查询的布尔操作返回零行时产生的错误消息。 此选项对于使用其布尔操作或 NEAR 操作包括干扰词的 CONTAINS 谓词的全文查询非常有用。
sp_configure 'show advanced options',1;
RECONFIGURE;
GO
sp_configure 'transform noise words',1;
RECONFIGURE;
GO