关于SQLServer2000的全文检索使用心得

原创于2008年06月28日,2009年10月18日迁移至此。


之前曾经指导 SQLServer2000 的全文检索功能,不过不太清楚它的实际操作步骤和功能,现特地作了一次完整的实验,对 SQLServer2000 的该功能,做了一番了解。

-- 验证全文检索服务是否安装

-- 通过储存过程 FULLTEXTSERVICEPROPERTY (返回有关全文服务级别属性的信息)来验证搜索服务(全文组件)是否安装。

-- Select fulltextserviceproperty ('IsFullTextInstalled')

-- 返回 1 表示已安装全文组件;

-- 返回 0 表示未安装全文组件;

-- 返回 Null 表示输入无效或发生错误。

Select fulltextserviceproperty ('IsFullTextInstalled')

-- 选一个数据库 进行全文检索

use fulltexttest

go

-- 从数据库中删除所有目录:

Exec sp_fulltext_database 'disable'

-- 打开数据库全文索引的支持

execute sp_fulltext_database 'enable'

go

-- 建立全文目录 ft_news ,新闻库

-- 使用不同参数进行全文目录的创建、重建、填充、删除

--create 创建

--rebuild 填充

--start_full 启动填充

--stop 删除

-- 以下执行新闻目录的创建

execute sp_fulltext_catalog 'ft_news', 'create'

go

-- titles 表建立全文索引数据元, PK_dtlmb,PK_dtxxb 是主键所建立的唯一索引,可由 sp_help titles 得知

--sp_fulltext_table [ @tabname = ] 'qualified_table_name'

--, [ @action = ] 'action'

--[ , [ @ftcat = ] 'fulltext_catalog_name'

--, [ @keyname = ] 'unique_index_name' ]

-- 为以下数据表分别创建主键

--alter table dtlmb add CONSTRAINT PK_dtlmb PRIMARY KEY CLUSTERED (t_dtlmb_ID)

--alter table dtxxb add CONSTRAINT PK_dtxxb PRIMARY KEY CLUSTERED (GUID)

-- 为全文索引对表进行标记

execute sp_fulltext_table 'dtlmb','create', 'ft_news', 'PK_dtlmb'

go

execute sp_fulltext_table 'dtxxb','create', 'ft_news', 'PK_dtxxb'

go

-- 设置全文索引列名

exec sp_fulltext_column 'dtlmb', 'dtlmlx', 'add'

go

exec sp_fulltext_column 'dtlmb', 'zt', 'add'

go

exec sp_fulltext_column 'dtlmb', 'cc', 'add'

go

exec sp_fulltext_column 'dtxxb', 'dtxxlmlx', 'add'

go

exec sp_fulltext_column 'dtxxb', 'zt', 'add'

go

exec sp_fulltext_column 'dtxxb', 'cc', 'add'

go

-- 激活全文索引

exec sp_fulltext_table 'dtlmb', 'activate'

go

exec sp_fulltext_table 'dtxxb', 'activate'

go

-- 填充全文索引目录

exec sp_fulltext_catalog 'ft_news', 'start_full'

GO

-- 检查全文目录填充情况,一共两张表 36 条记录花了 33 分钟

WHILE FulltextCatalogProperty('ft_news','PopulateStatus')<>0

BEGIN

-- 如果全文目录正处于填充状态,则等待 30 秒后再检测一次

WAITFOR DELAY '0:0:30'

END

-- 全文目录填充完成后,使用全文目录检索

-- 使用 contains freetext

select zt,cc from dtlmb

where contains(zt, 'xxx')

go

select zt,cc from dtlmb

where contains(*, '"xxx"')

go

select dtxxlmlx,zt,cc from dtxxb

where freetext(zt, 'xxx')

go

select dtxxlmlx,zt,cc from dtxxb

where freetext (*, '"xxx"')

go

Select * from dtxxb where zt like ‘%xxx%’

-- 与全文检索相比,从网络统计信息 -> 所接收的字节数 / 时间统计信息 -> 服务器应答累计等待时间 , 时间相差一个数据量级

-- 增量填充,即激活并传播跟踪更改

-- 当更改发生时,下面的示例激活并启动将所跟踪的更改传播到全文索引。

-- 如果表不包含 timestamp 列,则只能执行完全填充或更改跟踪填充

EXEC sp_fulltext_table dtlmb, 'Start_change_tracking' -- 启动全文索引的增量填充

EXEC sp_fulltext_table dtlmb, 'Start_background_updateindex' -- 在变化发生时,开始将跟踪的变化传播到全文索引。

-- 更改一条记录,大约过一分钟之后,便可通过全文检索查询到

SQLServer2000 企业管理 器中关于全文检索部分的功能和步骤

<!-- [if !supportLists]-->1、 从表上定义全文检索,即通过向导的方式,选择相应的全文目录和待查询的全文检索字段,系统会通过该表有无主键判断该表是否能够建立全文索引,同时也可实现对全文检索的调度。 <!-- [endif]-->

<!-- [if !supportLists]-->2、 编辑全文检索,功能同上,对一个已经存在的全文索引进行修改。 <!-- [endif]-->

<!-- [if !supportLists]-->3、 从表中删除全文索引,这个就不用说了 <!-- [endif]-->

<!-- [if !supportLists]-->4、 启动完全填充,全文检索建立之后,系统并不会自动填充索引内容,需要执行该任务或者脚本。 <!-- [endif]-->

如果为全文目录请求完全填充,则为该目录所涉及的所有表中的所有行生成索引项。如果为表请求完全填充,则为该表中的所有行生成索引项。完全填充通常发生在当首先填充目录或索引,然后使用更改跟踪或增量填充来维护索引时。

<!-- [if !supportLists]-->5、 启动增量填充 <!-- [endif]-->

<!-- [if !supportLists]-->6、 停止填充,停止当前的填充任务,不管是完全还是增量。 <!-- [endif]-->

<!-- [if !supportLists]-->7、 更改跟踪 <!-- [endif]-->

维护在系统表中已修改的行的记录,并将更改传播到全文索引。通过执行 sp_fulltext_table 启动更改跟踪并为 @action 参数指定 start_change_tracking 。使用更改跟踪时,也指定从历史表取得更改并在全文索引中填充更改的时间

<!-- [if !supportLists]-->8、 更新后台中的索引 <!-- [endif]-->

<!-- [if !supportLists]-->9、 更新索引 <!-- [endif]-->

<!-- [if !supportLists]-->10、 调度,建立一个调度任务指定时间对数据进行全文检索更新 <!-- [endif]-->

<!-- [if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><v:stroke joinstyle="miter"/><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"/><v:f eqn="sum @0 1 0"/><v:f eqn="sum 0 0 @1"/><v:f eqn="prod @2 1 2"/><v:f eqn="prod @3 21600 pixelWidth"/><v:f eqn="prod @3 21600 pixelHeight"/><v:f eqn="sum @0 0 1"/><v:f eqn="prod @6 1 2"/><v:f eqn="prod @7 21600 pixelWidth"/><v:f eqn="sum @8 21600 0"/><v:f eqn="prod @7 21600 pixelHeight"/><v:f eqn="sum @10 21600 0"/></v:formulas><v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/><o:lock v:ext="edit" aspectratio="t"/></v:shapetype><v:shape id="_x0000_i1025" type="#_x0000_t75" style='width:374.25pt; height:313.5pt'><v:imagedata src="file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtml1/01/clip_image001.png" o:title=""/></v:shape><![endif]--><!-- [if !vml]-->

你可能感兴趣的:(sqlserver2000)