坏消息:没有办法。好消息:你不需要它(因为它无论如何也无济于事)。
我在其中一个项目中遇到了类似的问题。我的理解是,在构建全文索引时,SQL Server会将所有特殊字符视为单词分隔符,因此:
考虑我们下面的表格以及相应的全文索引(它被跳过):
CREATE TABLE [dbo]。[ActicleTable]
(
[Id] int identity(1,1)not null primary key,
[ ActicleBody] varchar(max)not null
);
稍后我们将表添加到行:
INSERT INTO [ActicleTable] values('digitally improvements folders')
INSERT INTO [ActicleTable] values('digitally improve {ments} fold(ers)')
尝试搜索:
SELECT * FROM [ArticleTable] WHERE CONTAINS(*,'digitally')
SELECT * FROM [ArticleTable] WHERE CONTAINS(*,'improvements')
SELECT * FROM [ArticleTable] WHERE CONTAINS(*,'folders')
和
SELECT * FROM [ArticleTable] WHERE CONTAINS(*,'digital')
SELECT * FROM [ArticleTable] WHERE CONTAINS(*,'improve')
SELECT * FROM [ArticleTable] WHERE CONTAINS(*,'fold')
第一组条件匹配第一行(而不是第二行),而第二组匹配第二行。
不幸的是我找不到al墨迹到MSDN(或其他地方),这些行为是明确陈述的。但是我找到了,它告诉如何将引号全文搜索查询,这与上述算法[隐含地]一致。
I am doing a MS SQL Server Full Text Search query. I need to escape special characters so I can search on a specific term that contains special characters. Is there a built-in function to escape a full text search string ? If not, how would you do it ?
Bad news: there's no way. Good news: you don't need it (as it won't help anyway).
I've faced similar issue on one of my projects. My understanding is that while building full-text index, SQL Server treats all special characters as word delimiters and hence:
Consider we have the following table with a corresponding full-text index for it (which is skipped):
CREATE TABLE [dbo].[ActicleTable]
(
[Id] int identity(1,1) not null primary key,
[ActicleBody] varchar(max) not null
);
Consider later we add rows to the table:
INSERT INTO [ActicleTable] values ('digitally improvements folders')
INSERT INTO [ActicleTable] values ('digital"ly improve{ments} fold(ers)')
Try searching:
SELECT * FROM [ArticleTable] WHERE CONTAINS(*, 'digitally')
SELECT * FROM [ArticleTable] WHERE CONTAINS(*, 'improvements')
SELECT * FROM [ArticleTable] WHERE CONTAINS(*, 'folders')
and
SELECT * FROM [ArticleTable] WHERE CONTAINS(*, 'digital')
SELECT * FROM [ArticleTable] WHERE CONTAINS(*, 'improve')
SELECT * FROM [ArticleTable] WHERE CONTAINS(*, 'fold')
First group of conditions will match first row (and not the second) while the second group will match second row only.
Unfortunately I could not find a link to MSDN (or something) where such behaviour is clearly stated. But I've found an official article that tells how to convert quotation marks for full-text search queries, which is [implicitly] aligned with the above described algorithm.
这篇关于SQL Server全文搜索转义字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!