最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

SQLSERVER全文搜索

来源:动视网 责编:小采 时间:2020-11-09 07:39:01
文档

SQLSERVER全文搜索

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

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

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

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

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

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

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

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

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

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

noiseCHS.txt文件的内容

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

View Code

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

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


爬网日志

MSDN中关于爬网的描述

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

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

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

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

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

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

View Code

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

在我摘抄的文章里有提到

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

Microsoft Search 服务


全文索引碎片

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

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

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

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

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

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

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

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

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

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


总结

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

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

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

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

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

文章写到这里了,如有不对的地方,欢迎大家拍砖哦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为简体中文




 0
 
 Internet Explorer
 IE
 IE5
 
 
 NT5
 W2K
 Windows 2000
 
 
 run
 jog
 
 
-->

文档

SQLSERVER全文搜索

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

最新推荐

猜你喜欢

热门推荐

专题
Top