二进制字段上的MSSQL全文搜索不会产生任何结果

时间:2018-02-07 14:45:01

标签: sql-server indexing full-text-search

我有一个MS SQL数据库,其中包含一个表,其中包含各种文档(Word,Excel,PDF等)的二进制图像。 我为FullTextSearch安装了Office过滤器。

我跑了:

EXEC sp_fulltext_service 'load_os_resources', 1
exec sp_fulltext_service 'update_languages';
EXEC sp_fulltext_service 'restart_all_fdhosts'

有问题的表有一个内容(Varbinary(MAX))字段,其中包含文件的实际二进制内容和mime类型字段。 我添加了一个新列,用于评估mime类型并设置正确的文档扩展名:

alter table core.DocumentObjectContent
add Extension as (case when contenttype = 'application/msword' then '.doc'
                              when contenttype = 'application/vnd.openxmlformats-officedocument.presentationml.presentation' then '.pptx'
                              when contenttype = 'application/pdf' then '.pdf'
                              when contenttype = 'application/vnd.ms-excel' then '.xls'
                              when contenttype = 'application/vnd.ms-powerpoint' then '.ppt'
                              when contenttype = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' then '.xlsx'
                              when contenttype = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' then '.docx' end)

我创建了全文搜索目录:

CREATE FULLTEXT CATALOG ftCatalogY AS DEFAULT;
CREATE FULLTEXT INDEX ON core.DocumentObjectContent(content Type column extension) KEY INDEX PK_DocumentObjectContent ON ftCatalogY;

它构建了索引,但索引似乎是空的:

此查询:

SELECT * FROM sys.dm_fts_index_population

显示FTS指数为"开始"。并且对sys.fulltextcatalogs表的查询返回" Idle"状态。

一个简单的选择:

select * 
from core.DocumentObjectContent
where contains(content, 'a')

不会返回任何结果。

有谁知道我做错了什么?让我抓狂:)

1 个答案:

答案 0 :(得分:0)

我最终发现了问题所在:文档被保存为gzip,这就是FTS无法正常工作的原因。使用SQL中的DECOMPRESS并基于该视图的FTS对它们进行了查看。立即行动。