ホームページ  >  記事  >  データベース  >  SQLSERVER全文搜索

SQLSERVER全文搜索

WBOY
WBOYオリジナル
2016-06-07 15:44:391372ブラウズ

SQLSERVER全文搜索 看这篇文章之前请先看一下下面我摘抄的全文搜索的MSDN资料,基本上MSDN上关于全文搜索的资料的我都copy下来了 并且非常认真地阅读和试验了一次,并且补充了一些SQL语句,这篇文章本人抽取了一些本人自认为是重点的出来 并且加入了一些自己

SQLSERVER全文搜索

看这篇文章之前请先看一下下面我摘抄的全文搜索的MSDN资料,基本上MSDN上关于全文搜索的资料的我都copy下来了

并且非常认真地阅读和试验了一次,并且补充了一些SQL语句,这篇文章本人抽取了一些本人自认为是重点的出来

并且加入了一些自己的内容,补充MSDN上没有的和整理了网上关于全文搜索的资料

至于全文搜索的性能注意事项,大家可以看我copy下来的文章

文章地址:http://www.cnblogs.com/lyhabc/articles/3254782.html

网上另一篇说全文搜索的也比较详细

SQL Server 全文目录相关 地址:http://www.cnblogs.com/dreamontheway/archive/2010/08/19/1809963.html

至于什么是全文搜索我就不说了,网上文章非常多,但是这些文章感觉总结和归纳不全,只是建立一下全文索引,但是并没有深入一些或者再整理一下

http://msdn.microsoft.com/zh-cn/library/ms142571.aspx
http://msdn.microsoft.com/zh-cn/library/ms142497.aspx
http://msdn.microsoft.com/zh-cn/library/ms142575.aspx
http://msdn.microsoft.com/zh-cn/library/ms142560.aspx
http://msdn.microsoft.com/zh-cn/library/cc879261(v=SQL.105).aspx
http://msdn.microsoft.com/zh-cn/library/ms142505(v=SQL.105).aspx


全文搜索的架构

先上MSDN的一幅图片

SQLSERVER全文搜索

 

我画了一幅简单的图

SQLSERVER全文搜索

其实全文搜索技术也有些人叫全文搜索或者叫全文索引,不过两种叫法本人都觉得是对的

MSDN中对于普通SQLSERVER和全文索引的区别

 

全文索引

普通 SQL Server 索引

每个表只允许有一个全文索引。

每个表允许有多个普通索引。

将数据添加到全文索引的操作称为“填充”,可以通过计划或特定请求来请求填充,也可以在添加新数据时自动填充。

当插入、更新或删除作为其基础的数据时自动更新。

在同一个数据库内分组为一个或多个全文目录。

不分组。

 

在一张表中建立了全文索引后,你不会看到数据表中会有全文索引页面,因为MSDN说得很清楚,

因为全文索引的行以压缩格式存储在磁盘的文件系统里,以优化磁盘的使用,并且这些数据会以二进制数据的形式存储。

SQLSERVER全文搜索

创建全文目录的时候会有一个选项叫你选择目录位置,全文索引就存放在这个位置

当你查询全文索引列的时候,SQLSERVER就会扫描全文目录,去找你需要查询的记录,所以当你查看执行计划的时候会看到一个执行计划“远程扫描

远程扫描基本上占了大头

SQLSERVER全文搜索

 


全SQL建立全文搜索

在网上看到很多文章都是用SSMS来建立全文索引,本人想用全SQL的方式建立全文索引因为高手都是使用TSQL而非GUI,虽然本人不是高手o(∩_∩)o

(1)先在D盘建立一个文件夹fulltext

建立全文索引的方式有两种

<span> 1</span> <span>USE</span> <span>[</span><span>pratice</span><span>]</span>
<span> 2</span> <span>GO</span>
<span> 3</span> 
<span> 4</span> 
<span> 5</span> 
<span> 6</span> <span>--</span><span>创建全文索引的方式1:</span>
<span> 7</span> 
<span> 8</span> <span>--</span><span>-----------开启全文索引和创建全文索引目录  全文目录创建的路径是D:\fulltext</span>
<span> 9</span> <span>--</span><span>fulltext_pratice是自己自定义的全文目录名称</span>
<span>10</span> <span>EXEC</span> <span>[</span><span>sys</span><span>]</span>.<span>[</span><span>sp_fulltext_database</span><span>]</span> <span>@action</span> <span>=</span> <span>'</span><span>enable</span><span>'</span> <span>--</span><span> varchar(20)</span>
<span>11</span> 
<span>12</span> <span>--</span><span>如果数据库中已存在全文目录fulltext_pratice要先drop掉</span>
<span>13</span> <span>--</span><span>EXEC [sys].[sp_fulltext_catalog] @ftcat = 'fulltext_pratice', -- sysname</span>
<span>14</span> <span>--</span><span>    @action = 'drop' -- varchar(20)</span>
<span>15</span>     
<span>16</span> <span>EXEC</span> <span>[</span><span>sys</span><span>]</span>.<span>[</span><span>sp_fulltext_catalog</span><span>]</span> <span>@ftcat</span> <span>=</span> <span>'</span><span>fulltext_pratice</span><span>'</span>, <span>--</span><span> sysname</span>
<span>17</span>     <span>@action</span> <span>=</span> <span>'</span><span>create</span><span>'</span>, <span>--</span><span> varchar(20)</span>
<span>18</span>     <span>@path</span> <span>=</span> N<span>'</span><span>D:\fulltext</span><span>'</span> <span>--</span><span> nvarchar(101)</span>

 

建立[fulltext_test]表 下面打算在id字段上建立全文索引, 建立全文索引的列的要求是not null并且是唯一的!!!

<span> 1</span> <span>CREATE</span> <span>TABLE</span> <span>[</span><span>dbo</span><span>]</span>.<span>[</span><span>fulltext_test</span><span>]</span><span>(
</span><span> 2</span>     <span>[</span><span>id</span><span>]</span> <span>[</span><span>varchar</span><span>]</span>(<span>200</span>) <span>NOT</span> <span>NULL</span> <span>UNIQUE</span>,  <span>--</span><span>建立全文索引的列的要求是not null并且是唯一的!!!</span>
<span> 3</span>     <span>[</span><span>NAME</span><span>]</span> <span>[</span><span>varchar</span><span>]</span>(<span>200</span>) <span>NOT</span> <span>NULL</span>
<span> 4</span> ) <span>ON</span> <span>[</span><span>PRIMARY</span><span>]</span>
<span> 5</span> 
<span> 6</span> 
<span> 7</span> <span>--</span><span>在id字段上创建一个非聚集索引,并且是唯一的</span>
<span> 8</span> <span>CREATE</span> <span>UNIQUE</span> <span>NONCLUSTERED</span> <span>INDEX</span> <span>[</span><span>IX_ID</span><span>]</span> <span>ON</span> <span>[</span><span>dbo</span><span>]</span>.<span>[</span><span>fulltext_test</span><span>]</span> 
<span> 9</span> <span>(
</span><span>10</span>     <span>[</span><span>id</span><span>]</span> <span>ASC</span>
<span>11</span> )<span>WITH</span> (PAD_INDEX  <span>=</span> <span>OFF</span>, STATISTICS_NORECOMPUTE  <span>=</span> <span>OFF</span>, SORT_IN_TEMPDB <span>=</span> <span>OFF</span>, IGNORE_DUP_KEY <span>=</span> <span>OFF</span>, DROP_EXISTING <span>=</span> <span>OFF</span>, ONLINE <span>=</span> <span>ON</span>, ALLOW_ROW_LOCKS  <span>=</span> <span>ON</span>, ALLOW_PAGE_LOCKS  <span>=</span> <span>ON</span>) <span>ON</span> <span>[</span><span>PRIMARY</span><span>]</span>

为表[fulltext_test]创建全文索引 可索引列为 id

<span>1</span> <span>EXEC</span> <span>[</span><span>sys</span><span>]</span>.<span>[</span><span>sp_fulltext_table</span><span>]</span> <span>@tabname</span> <span>=</span> N<span>'</span><span>fulltext_test</span><span>'</span>, <span>--</span><span> nvarchar(517)</span>
<span>2</span>     <span>@action</span> <span>=</span> <span>'</span><span>create</span><span>'</span>, <span>--</span><span> varchar(50)</span>
<span>3</span>     <span>@ftcat</span> <span>=</span> fulltext_pratice, <span>--</span><span> sysname</span>
<span>4</span>     <span>@keyname</span> <span>=</span> IX_ID <span>--</span><span> sysname</span>

<span>1</span> <span>--</span><span>@language参数的意义在于分词,到时候会把id字段里的数据按照各个国家的语言来进行分词,具体的数字您可以自己指定</span>
<span>2</span> <span>--</span><span>2052代表中文,1033代表美文,2057代表英文</span>
<span>3</span> 
<span>4</span> <span>EXEC</span> <span>[</span><span>sys</span><span>]</span>.<span>[</span><span>sp_fulltext_column</span><span>]</span> <span>@tabname</span> <span>=</span> N<span>'</span><span>fulltext_test</span><span>'</span>, <span>--</span><span> nvarchar(517)</span>
<span>5</span>     <span>@colname</span> <span>=</span> id, <span>--</span><span> sysname</span>
<span>6</span>     <span>@action</span> <span>=</span> <span>'</span><span>add</span><span>'</span>, <span>--</span><span> varchar(20)</span>
<span>7</span>     <span>@language</span> <span>=</span> <span>2052</span> <span>--</span><span> int  2057 is the LCID for 英语  1033 :美语   2052:中文 </span>

至于SQLSERVER支持哪些国家的语言您可以使用下面SQL语句进行查询

<span>1</span> <span>SELECT</span> <span>*</span> <span>FROM</span>  sys.fulltext_languages 

SQLSERVER全文搜索

 

<span>1</span> <span>--</span><span>-----------激活索引</span>
<span>2</span> <span>EXEC</span> <span>[</span><span>sys</span><span>]</span>.<span>[</span><span>sp_fulltext_table</span><span>]</span> <span>@tabname</span> <span>=</span> N<span>'</span><span>fulltext_test</span><span>'</span>, <span>--</span><span> nvarchar(517)</span>
<span>3</span>     <span>@action</span> <span>=</span> <span>'</span><span>activate</span><span>'</span>

可以看到在全文目录的属性对话框里已经建立好全文索引

SQLSERVER全文搜索

我们先向[fulltext_test]表插入10行记录

<span> 1</span> <span>USE</span> <span>[</span><span>pratice</span><span>]</span>
<span> 2</span> <span>GO</span>
<span> 3</span> <span>INSERT</span> <span>INTO</span> <span>[</span><span>dbo</span><span>]</span>.<span>[</span><span>fulltext_test</span><span>]</span> ( <span>[</span><span>id</span><span>]</span>, <span>[</span><span>NAME</span><span>]</span><span> )
</span><span> 4</span> <span>SELECT</span> <span>'</span><span>1</span><span>'</span>,<span>'</span><span>中国</span><span>'</span> <span>UNION</span> <span>ALL</span>
<span> 5</span> <span>SELECT</span> <span>'</span><span>2</span><span>'</span>,<span>'</span><span>美国</span><span>'</span> <span>UNION</span> <span>ALL</span>
<span> 6</span> <span>SELECT</span> <span>'</span><span>3</span><span>'</span>,<span>'</span><span>英国</span><span>'</span> <span>UNION</span> <span>ALL</span>
<span> 7</span> <span>SELECT</span> <span>'</span><span>4</span><span>'</span>,<span>'</span><span>法国</span><span>'</span> <span>UNION</span> <span>ALL</span>
<span> 8</span> <span>SELECT</span> <span>'</span><span>5</span><span>'</span>,<span>'</span><span>韩国</span><span>'</span> <span>UNION</span> <span>ALL</span>
<span> 9</span> <span>SELECT</span> <span>'</span><span>6</span><span>'</span>,<span>'</span><span>日本</span><span>'</span> <span>UNION</span> <span>ALL</span>
<span>10</span> <span>SELECT</span> <span>'</span><span>7</span><span>'</span>,<span>'</span><span>朝鲜</span><span>'</span> <span>UNION</span> <span>ALL</span>
<span>11</span> <span>SELECT</span> <span>'</span><span>8</span><span>'</span>,<span>'</span><span>印度</span><span>'</span> <span>UNION</span> <span>ALL</span>
<span>12</span> <span>SELECT</span> <span>'</span><span>9</span><span>'</span>,<span>'</span><span>德国</span><span>'</span> <span>UNION</span> <span>ALL</span>
<span>13</span> <span>SELECT</span> <span>'</span><span>10</span><span>'</span>,<span>'</span><span>意大利</span><span>'</span> 

然后填充全文索引,至于什么是填充全文索引这里就不详细说了,我copy的MSDN里说得很清楚
http://www.cnblogs.com/lyhabc/articles/3254782.html

填充的方式有3种:1、完全填充,2、增量填充,3、自动跟踪更改

语法

<span>1</span> <span>ALTER</span> FULLTEXT <span>INDEX</span> <span>ON</span>  表名 <span>SET</span> CHANGE_TRACKING <span>OFF</span>

一般我们首次创建完全文索引之后先完全填充索引,然后修改填充方式为自动跟踪更改,等数据有变化的时候只需要把变化的部分填充进去全文索引里

<span> 1</span> <span>--</span><span>----------填充索引,首次创建完全文索引之后先完全填充索引,把数据全部放入全文索引里</span>
<span> 2</span> <span>USE</span> <span>[</span><span>pratice</span><span>]</span>
<span> 3</span> <span>GO</span>
<span> 4</span> <span>ALTER</span> FULLTEXT <span>INDEX</span> <span>ON</span> <span>[</span><span>dbo</span><span>]</span>.<span>[</span><span>fulltext_test</span><span>]</span> <span>SET</span> CHANGE_TRACKING <span>OFF</span>
<span> 5</span> <span>GO</span>
<span> 6</span> <span>ALTER</span> FULLTEXT <span>INDEX</span> <span>ON</span> <span>[</span><span>dbo</span><span>]</span>.<span>[</span><span>fulltext_test</span><span>]</span> START <span>FULL</span><span> POPULATION
</span><span> 7</span> <span>GO</span>
<span> 8</span> 
<span> 9</span> <span>--</span><span>----------修改填充方式为自动跟踪更改,等数据有变化的时候只需要把变化的部分填充进去全文索引里就可以了</span>
<span>10</span> <span>USE</span> <span>[</span><span>pratice</span><span>]</span>
<span>11</span> <span>GO</span>
<span>12</span> <span>ALTER</span> FULLTEXT <span>INDEX</span> <span>ON</span> <span>[</span><span>dbo</span><span>]</span>.<span>[</span><span>fulltext_test</span><span>]</span> <span>SET</span><span> CHANGE_TRACKING AUTO
</span><span>13</span> <span>GO</span>
<span>14</span> 
<span>15</span> 
<span>16</span> <span>--</span><span>-------------如果是增量填充</span>
<span>17</span> <span>USE</span> <span>[</span><span>pratice</span><span>]</span>
<span>18</span> <span>GO</span>
<span>19</span> <span>ALTER</span> FULLTEXT <span>INDEX</span> <span>ON</span> <span>[</span><span>dbo</span><span>]</span>.<span>[</span><span>fulltext_test</span><span>]</span> <span>SET</span> CHANGE_TRACKING <span>OFF</span>
<span>20</span> <span>GO</span>
<span>21</span> <span>--</span><span>或者</span>
<span>22</span> <span>ALTER</span> FULLTEXT <span>INDEX</span> <span>ON</span> <span>[</span><span>dbo</span><span>]</span>.<span>[</span><span>fulltext_test</span><span>]</span> <span>SET</span><span> CHANGE_TRACKING MANUAL
</span><span>23</span> <span>GO</span>
<span>24</span> <span>ALTER</span> FULLTEXT <span>INDEX</span> <span>ON</span> <span>[</span><span>dbo</span><span>]</span>.<span>[</span><span>fulltext_test</span><span>]</span><span> START INCREMENTAL POPULATION
</span><span>25</span> <span>GO</span>

 

增量填充的要求
增量填充是手动填充全文索引的一种替代机制。
您可以对 CHANGE_TRACKING 设置为 MANUAL 或 OFF 的全文索引运行增量填充。
如果全文索引的第一个填充是增量填充,它将对所有行编制索引并使其等效于完全填充。
增量填充要求索引表必须具有 timestamp 数据类型的列。 如果 timestamp 列不存在,则无法执行增量填充。
对不含 timestamp 列的表请求增量填充会导致完全填充操作。
另外,如果影响表全文索引的任意元数据自上次填充以来发生了变化,则增量填充请求将作为完全填充来执行。
这包括更改任何列、索引或全文索引定义所引起的元数据更改。
SQL Server 使用 timestamp 列标识自上次填充后发生更改的行。
然后,增量填充在全文索引中更新上次填充的当时或之后添加、删除或修改的行。
如果对表进行大量插入操作,则使用增量填充会较使用手动填充有效。
在填充结束时,全文引擎将记录新的 timestamp 值。 该值是 SQL 收集器遇到的最大 timestamp 值。
以后再启动增量填充时,将会使用此值。
若要运行增量填充,请执行使用 START INCREMENTAL POPULATION 子句的 ALTER FULLTEXT INDEX 语句

 

填充计划

当全文索引不是使用自动跟踪更改的时候就需要使用填充计划按照计划的时间去执行全文索引填充

填充计划分三种:

<span> 1</span> <span>--</span><span>(1)把自动跟踪更改设置为手动,然后UPDATE POPULATION更新填充</span>
<span> 2</span> <span>ALTER</span> FULLTEXT <span>INDEX</span> <span>ON</span> <span>[</span><span>dbo</span><span>]</span>.<span>[</span><span>fulltext_test</span><span>]</span> <span>SET</span><span> CHANGE_TRACKING MANUAL
</span><span> 3</span> <span>GO</span>
<span> 4</span> <span>ALTER</span> FULLTEXT <span>INDEX</span> <span>ON</span> <span>[</span><span>dbo</span><span>]</span>.<span>[</span><span>fulltext_test</span><span>]</span> START <span>UPDATE</span><span> POPULATION;
</span><span> 5</span> <span>GO</span>
<span> 6</span> 
<span> 7</span> <span>--</span><span>(2)把自动跟踪更改设置为手动或者关闭,然后INCREMENTAL POPULATION增量填充</span>
<span> 8</span> <span>ALTER</span> FULLTEXT <span>INDEX</span> <span>ON</span> <span>[</span><span>dbo</span><span>]</span>.<span>[</span><span>fulltext_test</span><span>]</span> <span>SET</span><span> CHANGE_TRACKING MANUAL
</span><span> 9</span> <span>GO</span>
<span>10</span> <span>--</span><span>或者</span>
<span>11</span> <span>ALTER</span> FULLTEXT <span>INDEX</span> <span>ON</span> <span>[</span><span>dbo</span><span>]</span>.<span>[</span><span>fulltext_test</span><span>]</span> <span>SET</span> CHANGE_TRACKING <span>OFF</span>
<span>12</span> <span>GO</span>
<span>13</span> <span>ALTER</span> FULLTEXT <span>INDEX</span> <span>ON</span> <span>[</span><span>dbo</span><span>]</span>.<span>[</span><span>fulltext_test</span><span>]</span><span> START INCREMENTAL POPULATION
</span><span>14</span> <span>GO</span>
<span>15</span> 
<span>16</span> <span>--</span><span>(3)把自动跟踪更改设置为关闭,然后进行完全填充,一般完全填充只在刚刚创建完全文索引的时候使用</span>
<span>17</span> <span>ALTER</span> FULLTEXT <span>INDEX</span> <span>ON</span> <span>[</span><span>dbo</span><span>]</span>.<span>[</span><span>fulltext_test</span><span>]</span> <span>SET</span> CHANGE_TRACKING <span>OFF</span>
<span>18</span> <span>GO</span>
<span>19</span> <span>ALTER</span> FULLTEXT <span>INDEX</span> <span>ON</span> <span>[</span><span>dbo</span><span>]</span>.<span>[</span><span>fulltext_test</span><span>]</span> START <span>FULL</span><span> POPULATION
</span><span>20</span> <span>GO</span>

 

大家都喜欢使用SSMS的GUI界面去创建填充计划,他们以为SQLSERVER没有提供TSQL给他们创建填充计划

实际上SSMS中的填充计划界面相当于创建作业的SQL语句

下面的SQL语句是创建增量填充计划的SQL语句,大家如果想使用更新填充的话,

只需要在sp_add_jobstep作业步骤里把@command更改为

如果想更改填充计划的执行间隔,开始时间只需要执行sp_add_jobschedule来修改就可以了

<span>1</span> <span>'</span><span>USE pratice ALTER FULLTEXT INDEX ON [dbo].[fulltext_test] SET CHANGE_TRACKING MANUAL
</span><span>2</span> 
<span>3</span> <span>ALTER FULLTEXT INDEX ON [dbo].[fulltext_test] START UPDATE POPULATION;
</span><span>4</span> 
<span>5</span> <span>'</span>


创建增量填充计划

<span> 1</span> <span>--</span><span>添加作业</span>
<span> 2</span> <span>USE</span> <span>[</span><span>msdb</span><span>]</span>
<span> 3</span> <span>GO</span>
<span> 4</span> <span>DECLARE</span> <span>@jobId</span> <span>BINARY</span>(<span>16</span><span>)
</span><span> 5</span> <span>EXEC</span> msdb.dbo.sp_add_job <span>@job_name</span> <span>=</span> N<span>'</span><span>启动对[fulltext_test]表增量填充</span><span>'</span>, <span>@enabled</span> <span>=</span> <span>1</span><span>,
</span><span> 6</span>     <span>@start_step_id</span> <span>=</span> <span>1</span><span>,
</span><span> 7</span>     <span>@description</span> <span>=</span> N<span>'</span><span>已为数据库pratice中的全文目录 fulltext_pratice 计划了对[fulltext_test]表的增量填充。</span><span>'</span><span>,
</span><span> 8</span>     <span>@job_id</span> <span>=</span> <span>@jobId</span><span> OUTPUT
</span><span> 9</span> <span>SELECT</span>  <span>@jobId</span>
<span>10</span> <span>GO</span>
<span>11</span> <span>--</span><span>---------------------------------------</span>
<span>12</span> <span>--</span><span>指定要运行本作业的服务器</span>
<span>13</span> <span>EXEC</span> msdb.dbo.sp_add_jobserver <span>@job_name</span> <span>=</span> N<span>'</span><span>启动对[fulltext_test]表增量填充</span><span>'</span><span>,
</span><span>14</span>     <span>@server_name</span> <span>=</span> N<span>'</span><span>joe</span><span>'</span>
<span>15</span> <span>GO</span>
<span>16</span> <span>--</span><span>------------------------------------</span>
<span>17</span> <span>--</span><span>添加作业计划</span>
<span>18</span> <span>USE</span> <span>[</span><span>msdb</span><span>]</span>
<span>19</span> <span>GO</span>
<span>20</span> <span>DECLARE</span> <span>@schedule_id</span> <span>INT</span>
<span>21</span> <span>EXEC</span> msdb.dbo.sp_add_jobschedule <span>@job_name</span> <span>=</span> N<span>'</span><span>启动对[fulltext_test]表增量填充</span><span>'</span><span>,
</span><span>22</span>     <span>@name</span> <span>=</span> N<span>'</span><span>fulltext_test</span><span>'</span>, <span>@enabled</span> <span>=</span> <span>1</span>, <span>@freq_type</span> <span>=</span> <span>4</span>, <span>@freq_interval</span> <span>=</span> <span>1</span><span>,
</span><span>23</span>     <span>@freq_subday_type</span> <span>=</span> <span>1</span>, <span>@freq_subday_interval</span> <span>=</span> <span>0</span><span>,
</span><span>24</span>     <span>@freq_relative_interval</span> <span>=</span> <span>0</span>, <span>@freq_recurrence_factor</span> <span>=</span> <span>1</span><span>,
</span><span>25</span>     <span>@active_start_date</span> <span>=</span> <span>20130815</span>, <span>@active_end_date</span> <span>=</span> <span>99991231</span><span>,
</span><span>26</span>     <span>@active_start_time</span> <span>=</span> <span>120742</span>, <span>@active_end_time</span> <span>=</span> <span>235959</span><span>,
</span><span>27</span>     <span>@schedule_id</span> <span>=</span> <span>@schedule_id</span><span> OUTPUT
</span><span>28</span> <span>SELECT</span>  <span>@schedule_id</span>
<span>29</span> <span>GO</span>
<span>30</span> <span>--</span><span>------------------------------------</span>
<span>31</span> <span>--</span><span>添加作业步骤</span>
<span>32</span> <span>USE</span> <span>[</span><span>msdb</span><span>]</span>
<span>33</span> <span>GO</span>
<span>34</span> <span>EXEC</span> msdb.dbo.sp_add_jobstep <span>@job_name</span> <span>=</span> N<span>'</span><span>启动对[fulltext_test]表增量填充</span><span>'</span><span>,
</span><span>35</span>     <span>@step_name</span> <span>=</span> N<span>'</span><span>全文索引</span><span>'</span>, <span>@step_id</span> <span>=</span> <span>1</span>, <span>@cmdexec_success_code</span> <span>=</span> <span>0</span><span>,
</span><span>36</span>     <span>@on_success_action</span> <span>=</span> <span>1</span>, <span>@on_success_step_id</span> <span>=</span> <span>-</span><span>1</span>, <span>@on_fail_action</span> <span>=</span> <span>2</span><span>,
</span><span>37</span>     <span>@on_fail_step_id</span> <span>=</span> <span>-</span><span>1</span>, <span>@retry_attempts</span> <span>=</span> <span>0</span>, <span>@retry_interval</span> <span>=</span> <span>0</span><span>,
</span><span>38</span>     <span>@os_run_priority</span> <span>=</span> <span>0</span>, <span>@subsystem</span> <span>=</span> N<span>'</span><span>TSQL</span><span>'</span>, <span>@command</span> <span>=</span> N<span>'</span>
<span>39</span> <span>    USE pratice
</span><span>40</span> <span>    ALTER FULLTEXT INDEX ON [dbo].[fulltext_test] SET CHANGE_TRACKING OFF
</span><span>41</span> 
<span>42</span> <span>    ALTER FULLTEXT INDEX ON [dbo].[fulltext_test] START INCREMENTAL POPULATION
</span><span>43</span> 
<span>44</span> <span>'</span>, <span>@database_name</span> <span>=</span> N<span>'</span><span>master</span><span>'</span>
<span>45</span> <span>GO</span>

 SQLSERVER全文搜索

SQLSERVER全文搜索

SQLSERVER全文搜索

创建全文索引的方式2: 方式2我没有找到全文目录的路径在哪里指定@path

<span> 1</span> <span>--</span><span>-----------------------------------------------------------------------</span>
<span> 2</span> <span>--</span><span>创建全文索引的方式2: 方式2我没有找到全文目录的路径在哪里指定@path</span>
<span> 3</span> <span>USE</span> <span>[</span><span>pratice</span><span>]</span>
<span> 4</span> <span>GO</span>
<span> 5</span> 
<span> 6</span> <span>CREATE</span> FULLTEXT <span>INDEX</span> <span>ON</span><span> 表名
</span><span> 7</span> <span>(
</span><span> 8</span>     字段名                         <span>--</span><span>Full-text index column name</span>
<span> 9</span>     TYPE <span>COLUMN</span> FileExtension    <span>--</span><span>Name of column that contains file type information</span>
<span>10</span>     Language <span>2052</span>                 <span>--</span><span>2057 is the LCID for British English</span>
<span>11</span> <span>)
</span><span>12</span> <span>KEY</span> <span>INDEX</span> <span>[</span><span>IX_ID</span><span>]</span> <span>ON</span> fulltext_pratice <span>--</span><span>Unique index</span>
<span>13</span> <span>WITH</span> CHANGE_TRACKING AUTO            <span>--</span><span>Population type; 填充类型为自动跟踪更改</span>
<span>14</span> <span>GO</span>
<span>15</span> <span>--</span><span>---------------------------------------------------</span>

 

卸载全文索引

<span>1</span> <span>--</span><span>---------------------卸载全文索引------------------</span>
<span>2</span> <span>EXEC</span> sp_fulltext_table <span>'</span><span>fulltext_test</span><span>'</span>, <span>'</span><span>deactivate</span><span>'</span>
<span>3</span> <span>EXEC</span> sp_fulltext_column <span>'</span><span>fulltext_test</span><span>'</span>, <span>'</span><span>id</span><span>'</span>, <span>'</span><span>drop</span><span>'</span>
<span>4</span> <span>EXEC</span> sp_fulltext_table <span>'</span><span>fulltext_test</span><span>'</span>, <span>'</span><span>drop</span><span>'</span>
<span>5</span> <span>EXEC</span> sp_fulltext_catalog <span>'</span><span>fulltext_pratice</span><span>'</span>, <span>'</span><span>stop</span><span>'</span>
<span>6</span> <span>EXEC</span> sp_fulltext_catalog <span>'</span><span>fulltext_pratice</span><span>'</span>, <span>'</span><span>drop</span><span>'</span>

 


分词和非索引字

SQLSERVER会根据创建全文索引的时候指定的国家语言来对数据进行分词和排除非索引字

比如下面指定2052就是按照中文的意思去对数据进行分词

<span>1</span> <span>EXEC</span> <span>[</span><span>sys</span><span>]</span>.<span>[</span><span>sp_fulltext_column</span><span>]</span> <span>@tabname</span> <span>=</span> N<span>'</span><span>fulltext_test</span><span>'</span>, <span>--</span><span> nvarchar(517)</span>
<span>2</span>     <span>@colname</span> <span>=</span> id, <span>--</span><span> sysname</span>
<span>3</span>     <span>@action</span> <span>=</span> <span>'</span><span>add</span><span>'</span>, <span>--</span><span> varchar(20)</span>
<span>4</span>     <span>@language</span> <span>=</span> <span>2052</span>

还有一个就是非索引字,在全文查询的过程当中会排除这些非索引字
MSDN中的解释:

非索引字表。提供系统非索引字表,该非索引字表包含一组基本非索引字(也称为干扰词)。
“非索引字”是对搜索没有任何帮助并且被全文查询忽略的词。 例如,在英语区域设置中,
诸如“a”、“and”、“is”和“the”之类的词都被视为非索引字。 通常情况下
,需要配置一个或多个同义词库文件和非索引字表。 有关详细信息,请参阅为全文搜索配置和管理非索引字和非索引字表。

这里非索引字表实际上就是指下面路径下的噪声文件,因为我的SQLSERVER安装在C盘

C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\FTData

默认的全文目录也会在这个路径下创建如果你创建全文目录的时候不指定全文目录的路径的话

SQLSERVER全文搜索

这些文件里存储了各个国家语言的一些噪声/干扰词

这些噪声文件是怎麽起作用的?

看一下下面的SQL语句,按道理应该可以查询出数据出来,但是。。。

<span>1</span> <span>USE</span><span> pratice
</span><span>2</span> <span>GO</span>
<span>3</span> <span>SELECT</span> <span>*</span>  <span>FROM</span> <span>[</span><span>dbo</span><span>]</span>.<span>[</span><span>fulltext_test</span><span>]</span> <span>WHERE</span> <span>CONTAINS</span>(id ,<span>'</span><span>5</span><span>'</span>)

 

SQLSERVER全文搜索

SQLSERVER全文搜索

因为5存储在noiseCHS.txt这个噪声文件里,所以填充全文索引的时候不会把5这个单词填充进去全文索引

如果想填充进去全文索引有一个办法,把noiseCHS.txt文件里第二行$1234567890删除了就可以了

SQLSERVER全文搜索

noiseCHS.txt文件的内容

SQLSERVER全文搜索SQLSERVER全文搜索

<span>  1</span> <span>?about
</span><span>  2</span> $ <span>1</span> <span>2</span> <span>3</span> <span>4</span> <span>5</span> <span>6</span> <span>7</span> <span>8</span> <span>9</span> <span>0</span><span> _
</span><span>  3</span> <span>a b c d e f g h i j k l m n o p q r s t u v w x y z
</span><span>  4</span> <span>after
</span><span>  5</span> <span>all</span>
<span>  6</span> <span>also
</span><span>  7</span> <span>an
</span><span>  8</span> <span>and</span>
<span>  9</span> <span>another
</span><span> 10</span> <span>any</span>
<span> 11</span> <span>are
</span><span> 12</span> <span>as</span>
<span> 13</span> <span>at
</span><span> 14</span> <span>be
</span><span> 15</span> <span>because
</span><span> 16</span> <span>been
</span><span> 17</span> <span>before
</span><span> 18</span> <span>being
</span><span> 19</span> <span>between</span>
<span> 20</span> <span>both
</span><span> 21</span> <span>but
</span><span> 22</span> <span>by</span>
<span> 23</span> <span>came
</span><span> 24</span> <span>can
</span><span> 25</span> <span>come
</span><span> 26</span> <span>could
</span><span> 27</span> <span>did
</span><span> 28</span> <span>do
</span><span> 29</span> <span>each
</span><span> 30</span> <span>for</span>
<span> 31</span> <span>from</span>
<span> 32</span> <span>get
</span><span> 33</span> <span>got
</span><span> 34</span> <span>had
</span><span> 35</span> <span>has
</span><span> 36</span> <span>have
</span><span> 37</span> <span>he
</span><span> 38</span> <span>her
</span><span> 39</span> <span>here
</span><span> 40</span> <span>him
</span><span> 41</span> <span>himself
</span><span> 42</span> <span>his
</span><span> 43</span> <span>how
</span><span> 44</span> <span>if</span>
<span> 45</span> <span>in</span>
<span> 46</span> <span>into</span>
<span> 47</span> <span>is</span>
<span> 48</span> <span>it
</span><span> 49</span> <span>like</span>
<span> 50</span> <span>make
</span><span> 51</span> <span>many
</span><span> 52</span> <span>me
</span><span> 53</span> <span>might
</span><span> 54</span> <span>more
</span><span> 55</span> <span>most
</span><span> 56</span> <span>much
</span><span> 57</span> <span>must
</span><span> 58</span> <span>my
</span><span> 59</span> <span>never
</span><span> 60</span> <span>now
</span><span> 61</span> <span>of</span>
<span> 62</span> <span>on</span>
<span> 63</span> <span>only</span>
<span> 64</span> <span>or</span>
<span> 65</span> <span>other
</span><span> 66</span> <span>our
</span><span> 67</span> <span>out
</span><span> 68</span> <span>over</span>
<span> 69</span> <span>said
</span><span> 70</span> <span>same
</span><span> 71</span> <span>see
</span><span> 72</span> <span>should
</span><span> 73</span> <span>since
</span><span> 74</span> <span>some</span>
<span> 75</span> <span>still
</span><span> 76</span> <span>such
</span><span> 77</span> <span>take
</span><span> 78</span> <span>than
</span><span> 79</span> <span>that
</span><span> 80</span> <span>the
</span><span> 81</span> <span>their
</span><span> 82</span> <span>them
</span><span> 83</span> <span>then</span>
<span> 84</span> <span>there
</span><span> 85</span> <span>these
</span><span> 86</span> <span>they
</span><span> 87</span> <span>this
</span><span> 88</span> <span>those
</span><span> 89</span> <span>through
</span><span> 90</span> <span>to</span>
<span> 91</span> <span>too
</span><span> 92</span> <span>under
</span><span> 93</span> <span>up
</span><span> 94</span> <span>very
</span><span> 95</span> <span>was
</span><span> 96</span> <span>way
</span><span> 97</span> <span>we
</span><span> 98</span> <span>well
</span><span> 99</span> <span>were
</span><span>100</span> <span>what
</span><span>101</span> <span>where</span>
<span>102</span> <span>which
</span><span>103</span> <span>while</span>
<span>104</span> <span>who
</span><span>105</span> <span>with</span>
<span>106</span> <span>would
</span><span>107</span> <span>you
</span><span>108</span> <span>your
</span><span>109</span> <span>的
</span><span>110</span> <span>一
</span><span>111</span> <span>不
</span><span>112</span> <span>在
</span><span>113</span> <span>人
</span><span>114</span> <span>有
</span><span>115</span> <span>是
</span><span>116</span> <span>为
</span><span>117</span> <span>以
</span><span>118</span> <span>于
</span><span>119</span> <span>上
</span><span>120</span> <span>他
</span><span>121</span> <span>而
</span><span>122</span> <span>后
</span><span>123</span> <span>之
</span><span>124</span> <span>来
</span><span>125</span> <span>及
</span><span>126</span> <span>了
</span><span>127</span> <span>因
</span><span>128</span> <span>下
</span><span>129</span> <span>可
</span><span>130</span> <span>到
</span><span>131</span> <span>由
</span><span>132</span> <span>这
</span><span>133</span> <span>与
</span><span>134</span> <span>也
</span><span>135</span> <span>此
</span><span>136</span> <span>但
</span><span>137</span> <span>并
</span><span>138</span> <span>个
</span><span>139</span> <span>其
</span><span>140</span> <span>已
</span><span>141</span> <span>无
</span><span>142</span> <span>小
</span><span>143</span> <span>我
</span><span>144</span> <span>们
</span><span>145</span> <span>起
</span><span>146</span> <span>最
</span><span>147</span> <span>再
</span><span>148</span> <span>今
</span><span>149</span> <span>去
</span><span>150</span> <span>好
</span><span>151</span> <span>只
</span><span>152</span> <span>又
</span><span>153</span> <span>或
</span><span>154</span> <span>很
</span><span>155</span> <span>亦
</span><span>156</span> <span>某
</span><span>157</span> <span>把
</span><span>158</span> <span>那
</span><span>159</span> <span>你
</span><span>160</span> <span>乃
</span><span>161</span> 它
View Code

SQLSERVER全文搜索

这些非索引字的好处和对性能的影响大家可以查看我摘抄的文章

http://www.cnblogs.com/lyhabc/articles/3254782.html


爬网日志

MSDN中关于爬网的描述

全文填充(也称为爬网)开始后,全文引擎会将大批数据存入内存并通知筛选器后台程序宿主

在爬网的过程中会产生一些日志,称为爬网日志

爬网日志存放在下面这个路径

C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG

SQLSERVER全文搜索

我贴上其中一个日志的内容,里面都是一些关于填充的信息

SQLSERVER全文搜索SQLSERVER全文搜索

<span> 1</span> <span>2013</span><span>-</span><span>08</span><span>-</span><span>15</span> <span>22</span>:<span>27</span>:<span>27.59</span> spid18s     The <span>full</span><span>-</span><span>text</span> catalog monitor reported catalog "fulltext_pratice" (<span>16</span>) <span>in</span> <span>database</span> "pratice" (<span>5</span>) <span>in</span> REINITIALIZE state. This <span>is</span> an informational message <span>only</span>. No <span>user</span> action <span>is</span><span> required.
</span><span> 2</span> <span>2013</span><span>-</span><span>08</span><span>-</span><span>15</span> <span>22</span>:<span>27</span>:<span>27.59</span> spid19s     Informational: <span>Full</span><span>-</span><span>text</span> <span>Full</span> population initialized <span>for</span> <span>table</span> <span>or</span> indexed <span>view</span> <span>'</span><span>[pratice].[dbo].[fulltext_test]</span><span>'</span> (<span>table</span> <span>or</span> indexed <span>view</span> ID <span>'</span><span>667149422</span><span>'</span>, <span>database</span> ID <span>'</span><span>5</span><span>'</span>). Population sub<span>-</span>tasks: <span>1</span><span>.
</span><span> 3</span> <span>2013</span><span>-</span><span>08</span><span>-</span><span>15</span> <span>22</span>:<span>27</span>:<span>37.64</span> spid24s     Informational: <span>Full</span><span>-</span><span>text</span> <span>Full</span> population completed <span>for</span> <span>table</span> <span>or</span> indexed <span>view</span> <span>'</span><span>[pratice].[dbo].[fulltext_test]</span><span>'</span> (<span>table</span> <span>or</span> indexed <span>view</span> ID <span>'</span><span>667149422</span><span>'</span>, <span>database</span> ID <span>'</span><span>5</span><span>'</span>). <span>Number</span> <span>of</span> documents processed: <span>10</span>. <span>Number</span> <span>of</span> documents failed: <span>0</span>. <span>Number</span> <span>of</span> documents need retry: <span>0</span><span>.
</span><span> 4</span> <span>2013</span><span>-</span><span>08</span><span>-</span><span>15</span> <span>22</span>:<span>27</span>:<span>37.65</span> spid24s     Changing the status <span>to</span> MERGE <span>for</span> <span>full</span><span>-</span><span>text</span> catalog "fulltext_pratice" (<span>16</span>) <span>in</span> <span>database</span> "pratice" (<span>5</span>). This <span>is</span> an informational message <span>only</span>. No <span>user</span> action <span>is</span><span> required.
</span><span> 5</span> <span>2013</span><span>-</span><span>08</span><span>-</span><span>15</span> <span>22</span>:<span>28</span>:<span>45.54</span> spid24s     Informational: <span>Full</span><span>-</span><span>text</span> <span>Full</span> population initialized <span>for</span> <span>table</span> <span>or</span> indexed <span>view</span> <span>'</span><span>[pratice].[dbo].[fulltext_test]</span><span>'</span> (<span>table</span> <span>or</span> indexed <span>view</span> ID <span>'</span><span>667149422</span><span>'</span>, <span>database</span> ID <span>'</span><span>5</span><span>'</span>). Population sub<span>-</span>tasks: <span>1</span><span>.
</span><span> 6</span> <span>2013</span><span>-</span><span>08</span><span>-</span><span>15</span> <span>22</span>:<span>28</span>:<span>46.54</span> spid24s     Informational: <span>Full</span><span>-</span><span>text</span> <span>Full</span> population completed <span>for</span> <span>table</span> <span>or</span> indexed <span>view</span> <span>'</span><span>[pratice].[dbo].[fulltext_test]</span><span>'</span> (<span>table</span> <span>or</span> indexed <span>view</span> ID <span>'</span><span>667149422</span><span>'</span>, <span>database</span> ID <span>'</span><span>5</span><span>'</span>). <span>Number</span> <span>of</span> documents processed: <span>10</span>. <span>Number</span> <span>of</span> documents failed: <span>0</span>. <span>Number</span> <span>of</span> documents need retry: <span>0</span><span>.
</span><span> 7</span> <span>2013</span><span>-</span><span>08</span><span>-</span><span>15</span> <span>22</span>:<span>28</span>:<span>46.54</span> spid24s     Changing the status <span>to</span> MERGE <span>for</span> <span>full</span><span>-</span><span>text</span> catalog "fulltext_pratice" (<span>16</span>) <span>in</span> <span>database</span> "pratice" (<span>5</span>). This <span>is</span> an informational message <span>only</span>. No <span>user</span> action <span>is</span><span> required.
</span><span> 8</span> <span>2013</span><span>-</span><span>08</span><span>-</span><span>15</span> <span>22</span>:<span>28</span>:<span>46.92</span> spid24s     Informational: <span>Full</span><span>-</span><span>text</span> <span>Full</span> population initialized <span>for</span> <span>table</span> <span>or</span> indexed <span>view</span> <span>'</span><span>[pratice].[dbo].[fulltext_test]</span><span>'</span> (<span>table</span> <span>or</span> indexed <span>view</span> ID <span>'</span><span>667149422</span><span>'</span>, <span>database</span> ID <span>'</span><span>5</span><span>'</span>). Population sub<span>-</span>tasks: <span>1</span><span>.
</span><span> 9</span> <span>2013</span><span>-</span><span>08</span><span>-</span><span>15</span> <span>22</span>:<span>28</span>:<span>51.66</span> spid56      Informational: <span>Full</span><span>-</span><span>text</span> <span>Full</span> population <span>for</span> <span>table</span> <span>or</span> indexed <span>view</span> <span>'</span><span>[pratice].[dbo].[fulltext_test]</span><span>'</span> (<span>table</span> <span>or</span> indexed <span>view</span> ID <span>'</span><span>667149422</span><span>'</span>, <span>database</span> ID <span>'</span><span>5</span><span>'</span>) was cancelled <span>by</span>  <span>user</span><span>.
</span><span>10</span> <span>2013</span><span>-</span><span>08</span><span>-</span><span>15</span> <span>22</span>:<span>28</span>:<span>51.69</span> spid24s     Informational: <span>Full</span><span>-</span><span>text</span> <span>Full</span> population initialized <span>for</span> <span>table</span> <span>or</span> indexed <span>view</span> <span>'</span><span>[pratice].[dbo].[fulltext_test]</span><span>'</span> (<span>table</span> <span>or</span> indexed <span>view</span> ID <span>'</span><span>667149422</span><span>'</span>, <span>database</span> ID <span>'</span><span>5</span><span>'</span>). Population sub<span>-</span>tasks: <span>1</span><span>.
</span><span>11</span> <span>2013</span><span>-</span><span>08</span><span>-</span><span>15</span> <span>22</span>:<span>29</span>:<span>05.54</span> spid24s     Informational: <span>Full</span><span>-</span><span>text</span> <span>Full</span> population completed <span>for</span> <span>table</span> <span>or</span> indexed <span>view</span> <span>'</span><span>[pratice].[dbo].[fulltext_test]</span><span>'</span> (<span>table</span> <span>or</span> indexed <span>view</span> ID <span>'</span><span>667149422</span><span>'</span>, <span>database</span> ID <span>'</span><span>5</span><span>'</span>). <span>Number</span> <span>of</span> documents processed: <span>10</span>. <span>Number</span> <span>of</span> documents failed: <span>0</span>. <span>Number</span> <span>of</span> documents need retry: <span>0</span><span>.
</span><span>12</span> <span>2013</span><span>-</span><span>08</span><span>-</span><span>15</span> <span>22</span>:<span>29</span>:<span>05.54</span> spid24s     Changing the status <span>to</span> MERGE <span>for</span> <span>full</span><span>-</span><span>text</span> catalog "fulltext_pratice" (<span>16</span>) <span>in</span> <span>database</span> "pratice" (<span>5</span>). This <span>is</span> an informational message <span>only</span>. No <span>user</span> action <span>is</span><span> required.
</span><span>13</span> <span>2013</span><span>-</span><span>08</span><span>-</span><span>15</span> <span>22</span>:<span>29</span>:<span>05.54</span> spid26s     Informational: <span>Full</span><span>-</span><span>text</span> Auto population initialized <span>for</span> <span>table</span> <span>or</span> indexed <span>view</span> <span>'</span><span>[pratice].[dbo].[fulltext_test]</span><span>'</span> (<span>table</span> <span>or</span> indexed <span>view</span> ID <span>'</span><span>667149422</span><span>'</span>, <span>database</span> ID <span>'</span><span>5</span><span>'</span>). Population sub<span>-</span>tasks: <span>1</span>.
View Code

 

这里有个题外话,全文搜索也会用到操作系统的搜索服务

在我摘抄的文章里有提到

http://www.cnblogs.com/lyhabc/articles/3254782.html

Microsoft Search 服务

SQLSERVER全文搜索


全文索引碎片

全文索引跟聚集索引一样也是有索引碎片的,下面贴上MSDN中的一些与全文索引碎片有关的内容

因为全文索引通过索引键列与分词列表的映射来找到关键词
全文索引跟普通索引一样也是有碎片的,而产生碎片的原理跟普通的聚集索引一样,在更新、删除、修改之后产生
填充完成后,将触发最终的合并过程,以便将索引片断合并为一个主全文索引
请注意,由于合并索引碎片时必须读取和写入大量数据,所以主合并可能会耗费大量 I/O,但它不会阻塞传入的查询。
对大量数据进行主合并会创建一个长时间运行的事务,在检查点期间延迟事务日志的截断。
在这种情况下,事务日志可能会在完整恢复模式下显著增长。
此语句将执行一次“主合并”,主合并将碎片合并成一个更大的碎片,并从全文索引中删除所有过时的条目

至于全文索引碎片是怎样产生的,大家可以看一下本人摘抄文章的最后《全文索引的结构》,里面说得真是非常详细

http://www.cnblogs.com/lyhabc/articles/3254782.html

下面是查询全文索引的碎片量的多少和重组/重建全文索引的SQL语句

<span> 1</span> <span>--</span><span>查看全文索引碎片量</span>
<span> 2</span> <span>SELECT</span> <span>*</span> <span>FROM</span><span>  sys.fulltext_index_fragments
</span><span> 3</span> <span>GO</span>
<span> 4</span> 
<span> 5</span> <span>--</span><span>重组全文索引</span>
<span> 6</span> <span>ALTER</span><span> FULLTEXT CATALOG fulltext_test REORGANIZE
</span><span> 7</span> <span>GO</span>
<span> 8</span> <span>--</span><span>重建全文索引</span>
<span> 9</span> <span>ALTER</span><span> FULLTEXT CATALOG fulltext_test REBUILD
</span><span>10</span> <span>GO</span>

 SQLSERVER全文搜索

有一天群里面有人问,为什麽SQL ERRORLOG里有很多MERGE FOR FULL-TEXT的信息,实际上这个是全文索引在合并索引,

合并索引一般发生在索引填充之后,不单只在SQL ERRORLOG里能看到MERGE FOR FULL-TEXT的信息,爬网日志也能看到

SQLSERVER全文搜索

SQLSERVER全文搜索

如果想更多了解合并是怎样工作的可以看我摘抄的文章

http://www.cnblogs.com/lyhabc/articles/3254782.html


总结

比较:本人觉得不应该用全文索引和普通SQLSERVER索引去比较,因为两者的实现方式和机制完全不一样,没有可比性

 

不方便的地方:备份,还原,附加数据库非常不方便,需要特别指定全文目录的文件夹,是否需要附加全文目录,之前项目经理就是这个原因而放弃使用

全文搜索,他之前搞的一个网站的评论功能就需要使用全文搜索,听他说自从那次使用全文搜索之后现在都没有使用了,现在他使用like关键字来代替全文

但是,因为全文有分词,数据压缩,搜索条件比较灵活等功能所以个人觉得like关键字是没有办法和全文搜索比较的

由于全文目录里的所有文件存储的都是二进制数据,所以没有办法再深入研究了

SQLSERVER全文搜索

SQLSERVER全文搜索

 

文章写到这里了,如有不对的地方,欢迎大家拍砖哦o(∩_∩)o

 

2014-5-10补充

关于一篇fulltext搜索的帖子

帖子地址:http://social.msdn.microsoft.com/Forums/zh-CN/290ad5f6-c0cc-497d-89da-6936d9d3bb57/fulltext123?forum=sqlserverzhchs

Full-text搜索把“一二三”当成“123”??

我想你需要维护下同义词词典,或者限定language_term

同义词词典路径:http://technet.microsoft.com/zh-cn/library/ms142491.aspx#location

同义词词典:SQL_Server_install_path/Microsoft SQL Server/MSSQL.1/MSSQL/FTDATA/ tschs.xml

干扰词词典:SQL_Server_install_path/Microsoft SQL Server/MSSQL.1/MSSQL/FTDATA/ noiseChs.txt

Chs为简体中文

 

<span>XML ID<span>=</span>"Microsoft Search Thesaurus"<span>></span>

<span>!<span>--</span><span>  Commented out</span>

    <span>thesaurus xmlns<span>=</span>"x<span>-</span><span>schema</span>:tsSchema.xml"<span>></span>
    <span>diacritics_sensitive<span>></span><span>0</span><span></span>diacritics_sensitive<span>></span>
        <span>expansion<span>></span>
            <span>sub<span>></span>Internet Explorer<span></span>sub<span>></span>
            <span>sub<span>></span>IE<span></span>sub<span>></span>
            <span>sub<span>></span>IE5<span></span>sub<span>></span>
        <span></span>expansion<span>></span>
        <span>replacement<span>></span>
            <span>pat<span>></span>NT5<span></span>pat<span>></span>
            <span>pat<span>></span>W2K<span></span>pat<span>></span>
            <span>sub<span>></span>Windows <span>2000</span><span></span>sub<span>></span>
        <span></span>replacement<span>></span>
        <span>expansion<span>></span>
            <span>sub<span>></span>run<span></span>sub<span>></span>
            <span>sub<span>></span>jog<span></span>sub<span>></span>
        <span></span>expansion<span>></span>
    <span></span>thesaurus<span>></span>
<span>--</span><span>></span>
<span></span>XML<span>></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

SQLSERVER全文搜索

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。