In this article, the latest in our series on the SQL FILESTREAM feature, we are going to look at the synergy and interoperability with SQL Server Full Text search, another powerful SQL Server feature

在本文中,这是我们有关SQL FILESTREAM功能的最新文章,我们将研究与SQL Server全文搜索(另一个强大SQL Server功能)的协同作用和互操作性。

We can use SQL Server Full Text search to query on the columns containing character data. Suppose we have a column containing an employee names. We usually use the like operator to search against such column, but in this case, SQL Server needs to do a table scan to get the required data. SQL Server provides the ability to perform a SQL Server Full Text search against text columns. If we have millions of records in the SQL FILESTREAM table, it is difficult to search for the particular document containing a particular keyword without any index on it. SQL Server Full Text feature supports FILESTREAM tables as well. In this article, let us explore the combination of SQL FILESTREAM and .

我们可以使用SQL Server全文搜索来查询包含字符数据的列。 假设我们有一个包含员工姓名的列。 我们通常使用like运算符搜索此类列,但是在这种情况下,SQL Server需要进行表扫描以获取所需的数据。 SQL Server提供了对文本列执行SQL Server全文搜索的功能。 如果我们在SQL FILESTREAM表中有数百万条记录,则很难搜索包含特定关键字但没有索引的特定文档。 SQL Server全文功能也支持FILESTREAM表。 在本文中,让我们探索SQL FILESTREAM和的组合。

全文搜索安装 (Full Text search Installation)

We can install the SQL Server feature during the installation wizard for option ‘Full Text and Semantic Extractions’. In this article, I am using the SQL Server 2019 version.

我们可以在安装向导中为选项“全文本和语义提取”安装SQL Server功能。 在本文中,我正在使用SQL Server 2019版本。

It installs a new service ‘SQL Full Text Filter Daemon Launcher’. You can check the status in the SQL Server Configuration Manager.

它将安装新服务“ SQL全文过滤器守护程序启动器”。 您可以在SQL Server配置管理器中检查状态。

The SQL Server FILESTREAM feature stores files in the file system. If we have the documents in the file system for a SQL FILESTREAM table, we need to know the way to query for the FILESTREAM object. We have the following questions before we start exploring this feature.

SQL Server FILESTREAM功能将文件存储在文件系统中。 如果文件系统中有用于SQL FILESTREAM表的文档,则需要了解查询FILESTREAM对象的方法。 在开始探索此功能之前,我们有以下问题。

  • Is it possible to use SQL Server Full Text search on the SQL FILESTREAM objects? 是否可以对SQL FILESTREAM对象使用SQL Server全文搜索?
  • If we have the documents inside the file system, is it possible to search for a specific word from the document? 如果我们在文件系统中有文档,是否可以从文档中搜索特定单词?

先决条件: ( Pre-requisites: )

We should have the following things ready before we proceed with this article

在继续本文之前,我们应该准备以下事情

  • Full Text Service should be in running status 全文服务应处于运行状态
  • The SQL FILESTREAM feature should be enabled at the instance level SQL FILESTREAM功能应在实例级别启用
  • A SQL Server FILESTREAM enabled database 启用S​​QL Server FILESTREAM的数据库

准备环境 (Prepare the environment)

Let us create a new SQL FILESTREAM table for this article using the below query. We need to have a column to store the document type in the FILESTREAM table. A document type is the extension of the document such as DOC, DOCX, XLS,.PDF.

让我们使用以下查询为本文创建一个新SQL FILESTREAM表。 我们需要有一列将文档类型存储在FILESTREAM表中。 文档类型是文档的扩展名,例如DOC,DOCX,XLS,.PDF。

CREATE TABLE [dbo].[FILESTREAM_Documents]([DocumentID] [uniqueidentifier] ROWGUIDCOL  NOT NULL,[DocumentName] [varchar](128) NULL,[DocumentType] [varchar](10) NULL,[DocumentFS] [varbinary](max) FILESTREAM  NOT NULL,
UNIQUE NONCLUSTERED
([DocumentID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] FILESTREAM_ON [DemoFileStream]
GO

We can check the SQL FILESTREAM table properties using the sp_help command. In the following screenshot, you can look at the DocumentType column to store the files extension.

我们可以使用sp_help命令检查SQL FILESTREAM表属性。 在下面的屏幕快照中,您可以查看DocumentType列来存储文件扩展名。

sp_help '[FILESTREAM_Documents]'

We will insert the two documents in the FILESTREAM table.

我们将在FILESTREAM表中插入两个文档。

  1. DECLARE @File varbinary(MAX);
    SELECT
    @File = CAST(
    bulkcolumn as varbinary(max)
    )
    FROM
    OPENROWSET(BULK 'C:\sqlshack\Draft articles\ RS Scripter Load Log.txt', SINGLE_BLOB) as MyData; INSERT INTO [FILESTREAM_Documents]
    VALUES
    (
    NEWID(),
    RS Scripter Load Log,
    '.txt ,
    @File
    )
    
  2. DECLARE @File varbinary(MAX);
    SELECT
    @File = CAST(
    bulkcolumn as varbinary(max)
    )
    FROM
    OPENROWSET(BULK 'C:\Users\rajen_000\Documents\avis\PDF\SQL_Server_on_VMware-Best_Practices_Guide.pdf', SINGLE_BLOB) as MyData; INSERT INTO [FILESTREAM_Documents]
    VALUES
    (
    NEWID(),
    'SQL_Server_on_VMware-Best_Practices_Guide',
    '.PDF' ,
    @File
    )
    

We can verify both the files insert successfully in the SQL FILESTREAM table as per the following images.

我们可以按照以下图像验证两个文件均已成功插入SQL FILESTREAM表中。

We can also check these files in the FILESTREAM container as well.

我们也可以在FILESTREAM容器中检查这些文件。

We need to configure SQL Server Full Text search on this FILESTREAM table to query on the document. We need to do the following tasks to use SQL Server Full Text search.

我们需要在此FILESTREAM表上配置SQL Server全文本搜索,以对文档进行查询。 为了使用SQL Server全文搜索,我们需要执行以下任务。

  1. Create a Full Text catalog 创建全文目录
  2. Create a Full Text index on tables 在表上创建全文索引

Let us explore both the steps one by one.

让我们一步一步地探索这两个步骤。

创建全文目录 (Create a Full Text catalog)

We need to create the Full Text catalog first. In SSMS, expand the FILESTREAM database, go to storage, and right click on the ‘Full Text Catalogs’ and select ‘New Full Text Catalog’.

我们需要首先创建全文目录。 在SSMS中,展开FILESTREAM数据库,转到存储,然后右键单击“全文目录”,然后选择“新建全文目录”。

It opens the Full Text catalog window. Enter the name for the Full Text catalog and in the options make it as default catalog. We also have the option to make the accent sensitive to insensitive. Let us make the ‘Accent sensitivity’ insensitive.

它将打开“全文目录”窗口。 输入全文目录的名称,然后在选项中将其设为默认目录。 我们还可以选择使重音敏感。 让我们使“口音敏感度”不敏感。

We scripted out the Full Text catalog query using the ‘script’ option at the top.

我们使用顶部的“脚本”选项编写了全文目录查询的脚本。

USE [FileStreamDemoDB_test]
GO
CREATE FULLTEXT CATALOG [FSDocumentCatalog] WITH ACCENT_SENSITIVITY = OFF
AS DEFAULT
GO

在FILESTREAM表上创建全文索引 (Create a Full Text index on FILESTREAM tables)

The next step is to create a Full Text index using the Full Text catalog we just created. We are going to create the Full Text index on the ‘[DocumentFS]’ column that stores the metadata for the document stored in the file system.

下一步是使用我们刚创建的全文目录创建全文索引。 我们将在“ [DocumentFS]”列上创建“全文索引”,该索引存储存储在文件系统中的文档的元数据。

In the FILESTREAM, go the FILESTREAM table ‘[FILESTREAM_Documents]’, go to Full Text Index, and define Full Text index.

在FILESTREAM中,转到FILESTREAM表'[FILESTREAM_Documents]',转到“全文索引”,然后定义“全文索引”。

It opens up the SQL Server Full Text indexing wizard.

它打开SQL Server全文索引向导。

Click ‘Next’ and select the unique index for this table. We already have the index ‘ UQ__FILESTRE__1ABEEF6E7BA05CBB’ that you can see in the unique index list. If we do not have the unique index in the FILESTREAM table, we need to create it first.

单击“下一步”,然后为此表选择唯一索引。 我们已经有了索引'UQ__FILESTRE__1ABEEF6E7BA05CBB',您可以在唯一索引列表中看到该索引。 如果在FILESTREAM表中没有唯一索引,则需要首先创建它。

In the next page, we need to select the text-based column in which we want to perform the Full Text queries. We have selected the ‘documents’ FILESTREAM column. In the type column, we need to use the file extensions such as as.PDF, .txt. In the SQL FILESTREAM table ‘DocumentType’ column contains the file extension; therefore, we used this column in the ‘Type Column’. SQL Server Full Text uses the file extension to parse the data and provide the content for the specific word. We can also specify the language for the word breaker as well. Specifying the word breaker language is optional.

在下一页中,我们需要选择要在其中执行全文查询的基于文本的列。 我们选择了“文档” FILESTREAM列。 在类型列中,我们需要使用文件扩展名,例如.PDF,.txt。 在SQL FILESTREAM表的“ DocumentType”列中包含文件扩展名; 因此,我们在“类型列”中使用了此列。 SQL Server全文使用文件扩展名来解析数据并提供特定单词的内容。 我们还可以为分词系统指定语言。 指定分词系统语言是可选的。

As a routine activity, we can do the insert, update or delete on the SQL FILESTREAM column as per application requirement. In this, we do not want to track changes on this table manually. In the next page, we can select the tracking type for this table.

作为例行活动,我们可以根据应用程序要求在SQL FILESTREAM列上进行插入,更新或删除。 在这种情况下,我们不想手动跟踪此表上的更改。 在下一页中,我们可以选择此表的跟踪类型。

  1. Automatic: it will automatically track the changes in the FILESTREAM table for the Full Text index 自动 :它将自动跟踪FILESTREAM表中全文索引的更改
  2. Manual: We need to initiate the Full Text index population process manually
  3. 手册 :我们需要手动启动全文索引填充过程
  4. No Tracking: We do not want any changes to be tracked in the SQL FILESTREAM table 无跟踪 :我们不希望在SQL FILESTREAM表中跟踪任何更改

When we define the automatic or the manual tracking option, it first initiates a full population of the Full Text index.

当我们定义自动或手动跟踪选项时,它首先启动全文索引的全部填充。

We can create the Full Text catalog from the following page of the wizard as well. We have already created the Full Text catalog, therefore, select the Full Text catalog and go to the next screen. In this example, we do not want to specify the index filegroup and Full Text stoplist. We are going to leave these options as default.

我们也可以从向导的下一页创建全文目录。 我们已经创建了全文目录,因此,选择全文目录并转到下一个屏幕。 在此示例中,我们不想指定索引文件组和全文非索引字表。 我们将这些选项保留为默认值。

In the following page, we can define the Full Text catalog population schedule. It is an optional page. Therefore, skip this page.

在下一页中,我们可以定义“全文”目录的填充计划。 这是一个可选页面。 因此,请跳过此页面。

Now, verify the description of the work being performed by the Full Text catalog wizard and ‘Finish’ to start the process.

现在,验证“全文目录”向导正在执行的工作的描述,并单击“完成”以开始该过程。

In the following image, you can observe that we have created the Full Text index successfully on the FILESTREAM table.

在下图中,您可以观察到我们已经在FILESTREAM表上成功创建了全文索引。

Now we are ready to query the SQL FILESTREAM table using the Full Text index. Suppose we have a large number of documents in the FILESTREAM table and we want to know the list of documents containing a particular keyword. We can use the predicates CONTAINS and FREETEXT in the select statement to query using SQL Server Full Text search on the FILESTREAM table.

现在,我们准备使用全文索引查询SQL FILESTREAM表。 假设FILESTREAM表中有大量文档,并且我们想知道包含特定关键字的文档列表。 我们可以在select语句中使用谓词CONTAINS和FREETEXT来对FILESTREAM表使用SQL Server全文搜索进行查询。

Suppose we want to get the list of the document containing word ‘Server’. We can run the following query in the FILESTREAM database. You can notice query using the CONTAINS predicate to query using SQL Server Full Text search.

假设我们要获取包含单词“ Server”的文档列表。 我们可以在FILESTREAM数据库中运行以下查询。 您可以注意到使用CONTAINS谓词进行查询以使用SQL Server全文搜索进行查询。

select * from [FILESTREAM_Documents]
where contains ([DocumentFS],'Server')

It returns the document name for the specified condition.

它返回指定条件的文档名称。

Let us run another query to find out the document containing the word ‘VMWare’. In the following screenshot, you can see the name of the document after SQL Server Full Text search.

让我们运行另一个查询以查找包含单词“ VMWare”的文档。 在下面的屏幕快照中,您可以在SQL Server全文搜索之后看到文档的名称。

select * from [FILESTREAM_Documents]
where contains ([DocumentFS],'VMWare')

We can use the FREETEXT predicate to search for all the documents that contain the words ‘ VMware Best Practices Guide’.

我们可以使用FREETEXT谓词搜索包含单词“ VMware Best Practices Guide”的所有文档。

select * from [FILESTREAM_Documents]
where FREETEXT  ([DocumentFS],'VMware Best Practices Guide')

One more example to search the document having the word ‘GFM_Load_Reports.’

另一个示例搜索包含单词“ GFM_Load_Reports”的文档。

select * from [FILESTREAM_Documents]
where FREETEXT  ([DocumentFS],'GFM_Load_Reports')

We have defined the change tracking as automatic while creating the Full Text index. If there are any changes in the FILESTREAM table, it should track the changes automatically. We should be able to query the FILESTREAM table using the Full Text index for the changes as well. Let us insert one more PDF document in the FILESTREAM table using the following query.

在创建全文索引时,我们已将更改跟踪定义为自动。 如果FILESTREAM表中有任何更改,它将自动跟踪更改。 我们也应该能够使用全文索引查询FILESTREAM表以进行更改。 让我们使用以下查询在FILESTREAM表中再插入一个PDF文档。

DECLARE @File varbinary(MAX);
SELECT
@File = CAST(
bulkcolumn as varbinary(max)
)
FROM
OPENROWSET(BULK 'C:\Users\rajen_000\Documents\avis\PDF\asa_9_db_admin_guide.pdf', SINGLE_BLOB) as MyData; INSERT INTO [FILESTREAM_Documents]
VALUES
(
NEWID(),
'asa_9_db_admin_guide',
'.PDF' ,
@File
)

We have three documents in the FILESTREAM table now. FILESTREAM table contains the text and PDF documents in the FILESTREAM container.

现在,FILESTREAM表中有三个文档。 FILESTREAM表包含FILESTREAM容器中的文本和PDF文档。

In the new inserted document, we have the word Sybase while the other two documents do not contain that word. We should get only the latest document name if we search for the keyword ‘Sybase’. Execute the below query in the FILESTREAM database.

在新插入的文档中,我们有单词Sybase,而其他两个文档则不包含该单词。 如果搜索关键字“ Sybase”,则应该仅获得最新的文档名称。 在FILESTREAM数据库中执行以下查询。

select * from [FILESTREAM_Documents]
where Contains  ([DocumentFS],' Sybase')

In the result set, you can see we get the correct document name. We did not execute the full-index catalog full or incremental population manually.

在结果集中,您可以看到我们获得了正确的文档名称。 我们没有手动执行全部或增量填充的全索引目录。

结论 (Conclusion)

In the article, we explored the powerful combination of SQL FILESTREAM and SQL Server Full Text search. With the combination of these features, we can easily search for a required file or document with a particular keyword.

在本文中,我们探索了SQL FILESTREAM和SQL Server全文本搜索的强大组合。 结合使用这些功能,我们可以轻松搜索带有特定关键字的所需文件或文档。

目录 (Table of contents)

FILESTREAM in SQL Server
Managing data with SQL Server FILESTREAM tables
SQL Server FILESTREAM Database backup overview
Restoring a SQL Server FILESTREAM enabled database
SQL Server FILESTREAM database recovery scenarios
Working with SQL Server FILESTREAM – Adding columns and moving databases
SQL Server FILESTREAM internals overview
Importing SQL Server FILESTREAM data with SSIS packages
SQL Server FILESTREAM queries and Filegroups
Viewing SQL Server FILESTREAM data with SSRS
SQL Server FILESTREAM Database Corruption and Remediation
Export SQL Server FILESTREAM Objects with PowerShell and SSIS
SQL FILESTREAM and SQL Server Full Text search
SQL Server FILESTREAM and Replication
SQL Server FILESTREAM with Change Data Capture
Transaction log backups in a SQL FILESTREAM database
SQL FILESTREAM Compatibility with Database Snapshot, Mirroring, TDE and Log Shipping
SQL Server FILETABLE – the next generation of SQL FILESTREAM
Managing Data in SQL Server FILETABLEs
SQL Server FILETABLE Use Cases
SQL Server中的文件流
使用SQL Server FILESTREAM表管理数据
SQL Server FILESTREAM数据库备份概述
还原启用了SQL Server FILESTREAM的数据库
SQL Server FILESTREAM数据库恢复方案
使用SQL Server FILESTREAM –添加列和移动数据库
SQL Server FILESTREAM内部概述
使用SSIS包导入SQL Server FILESTREAM数据
SQL Server FILESTREAM查询和文件组
使用SSRS查看SQL Server FILESTREAM数据
SQL Server FILESTREAM数据库损坏和修复
使用PowerShell和SSIS导出SQL Server FILESTREAM对象
SQL FILESTREAM和SQL Server全文搜索
SQL Server FILESTREAM和复制
具有更改数据捕获功能SQL Server FILESTREAM
SQL FILESTREAM数据库中的事务日志备份
SQL FILESTREAM与数据库快照,镜像,TDE和日志传送的兼容性
SQL Server FILETABLE –下一代SQL FILESTREAM
在SQL Server FILETABLEs中管理数据
SQL Server FILETABLE用例

翻译自: https://www.sqlshack.com/sql-filestream-and-sql-server-full-text-search/

SQL FILESTREAM和SQL Server全文搜索相关推荐

  1. SQL Server全文搜索

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

  2. gkz cloud sql_使用Cloud SQL的Google App Engine全文搜索

    gkz cloud sql 许多Google AppEngine开发人员一直在等待全文搜索功能,特别是来自网络上最大的搜索引擎Google. 我很高兴看到Google团队正在努力,您可以在Google ...

  3. 使用Cloud SQL的Google App Engine全文搜索

    许多Google AppEngine开发人员一直在等待全文搜索功能,特别是来自网络上最大的搜索引擎Google. 很高兴看到Google团队正在努力,您可以在Google I / O 2011大会上签 ...

  4. 如何设置SQL Server 全文搜索

    面以在自己电脑上设置SQL数据库的全文检索为例. 如果在安装SQL Server 时,已经安装了全文检索的,可以跳过这一步操作:如果在安装SQL服务器时,没有设置安装全文检索功能的,可以采用再安装的方 ...

  5. SQL FILESTREAM数据库中的事务日志备份

    In the continuation of our SQL FILESTREAM article series, we'll be covering transaction log backups ...

  6. SQL FILESTREAM与数据库快照,镜像,TDE和日志传送的兼容性

    This article is the continuation of the SQL FILESTREAM series. 本文是SQL FILESTREAM系列的继续. SQL FILESTREA ...

  7. SQL Server中的全文搜索

    SQL Server中的全文搜索 一.概述 二.全文搜索查询 三.将全文搜索查询与 LIKE 谓词进行比较 四.全文搜索体系结构 4.1.SQL Server 进程 4.2.过滤器守护程序主机进程 五 ...

  8. 使用Microsoft SQL Server 2000全文搜索功能构建Web搜索应用程序 --作者:Andrew B. Cencini...

    [摘要]了解如何充分利用SQL Server 2000的全文搜索功能.本文包含有关实现最大吞吐量和最佳性能的几点提示和技巧. 概述 使用Microsoft© SQL Server 2000的全文搜索功 ...

  9. 全文搜索 (SQL Server) 修复

    http://msdn.microsoft.com/zh-cn/msdntv/ms189801.aspx  sp_fulltext_catalog (Transact-SQL) SQL Server ...

最新文章

  1. c语言考试经典编程题目及答案,经典练习C语言编程的题目及答案整理
  2. js如何实现扫描身份证识别_人脸识别是如何实现的
  3. nginx php 后缀名,nginx去掉php后缀名的方法
  4. 介绍SLICEM里的LUT如何形成RAM资源
  5. 本年度最成功科技IPO企业之一:Twilio股票一月暴涨167%
  6. 深入理解数据库核心技术
  7. 基于STM32的高精度频率计设计
  8. HTTP相关知识的总结
  9. 卡尺测量的最小范围_车间里常用的测量器具,别说没见过!
  10. python清理浏览器文件_URL可以在浏览器或wget中正常工作,但是从Python或cURL中清空...
  11. 50个面试官最喜欢问的java微服务面试题
  12. lay和lied_lay和lie的区别
  13. 2021年4月7日 关于三层交换机的配置及命令!!!
  14. 火狐flash debug配置
  15. 用UltraISO制作Ubuntu_18.04U盘启动盘
  16. 高一上册计算机应用基础,计算机应用基础高一期末考试试题及答案
  17. 云付注册推荐人怎么填?云付新手怎么操作
  18. openlayers+vue 仿百度罗盘功能(指北针)
  19. Clean Code(整洁代码)
  20. pytorch中的激励函数(详细版)

热门文章

  1. vb6.0 定义一个公共类_纠正网上的错误:能不能自定义一个类叫java.lang.System/String?...
  2. Vue 路由懒加载
  3. Node.js区块链开发pdf
  4. 2018中国域名大会-强调服务与网络信息安全
  5. 第五章、使用复合赋值和循环语句
  6. 使用7zip把jre集成到绿色运行程序内
  7. Uber CEO博鳌论坛采访:看好中国市场共享经济的发展模式
  8. php 抓取天气情况 www.weather.com.cn
  9. asp.net 模板页中 控件 ID和Name 的变化
  10. js获取页面宽度给JS div设宽度