【问题标题】:MSSQL Full Text search on binary field yields no results二进制字段上的 MSSQL 全文搜索不会产生任何结果
【发布时间】:2018-07-17 21:45:30
【问题描述】:

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

我跑了:

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

有问题的表有一个 content(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 表的查询返回“空闲”状态。

一个简单的选择:

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

不返回任何结果。

有人知道我做错了什么吗?让我发疯:)

【问题讨论】:

  • 可能是个愚蠢的问题,但您是否真的将文档导入DocumentObjectContent 表? SELECT count(1) from core.DocumentObjectContent 会为您返回什么?

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-21
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多