转义括号 [ 在 CONTAINS() 子句中?

Escaping Bracket [ in a CONTAINS() clause?(转义括号 [ 在 CONTAINS() 子句中?)
本文介绍了转义括号 [ 在 CONTAINS() 子句中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在全文 SQL Server contains() 查询中转义括号?我已经尝试了以下所有方法,没有有效:

How can I escape a bracket in a full-text SQL Server contains() query? I've tried all the following, none of which work:

CONTAINS(crev.RawText, 'arg[0]')
CONTAINS(crev.RawText, 'arg[[0]]')
CONTAINS(crev.RawText, 'arg\[0\]')

使用双引号确实有效,但它强制整个搜索成为一个词组,这是多词查询的一个亮点.

Using double quotes does work, but it forces the entire search to be a phrase, which is a showstopper for multiple word queries.

CONTAINS(crev.RawText, '"arg[0]"')

我真正想做的就是摆脱括号,但我似乎无法做到..

All I really want to do is escape the bracket, but I can't seem to do that..

推荐答案

您不必转义 [,因为它在全文搜索中没有特殊含义.但是,如果您确实需要搜索完全匹配项,则可以使用 "" 标记.

You don't have to escape the [ as it has no special meaning in Full Text Search. If you do need to search for an exact match though, you can use "" marks.

此外,您可以在单引号内使用多个":

Further, you can use multiple "" inside the single quotes:

CONTAINS('"word1" or "word2" or "word3"')

这也有效:

CONTAINS('"word1" and "word2" and "word3"')

双引号内的任何内容都被视为精确文本.因此,如果我要搜索 AdventureWorks 中 Production.ProductDescription 表的 Description 字段,我可以使用

Anything put inside the double quotes is treated as exact text. Thus if I were to do a search of the Description field of the Production.ProductDescription table in AdventureWorks, I could use

CONTAINS('shifting and "on or off-road"') 

并且它会找到与on or off-road"这个词组匹配的词 shift.

and it would find matches for the word shifting that also had the phrase "on or off-road".

唯一的特殊符号是 ~,它可以用来代替 NEAR 命令.

The only special symbol is the ~, it can be used in place of the NEAR command.

CONTAINS('shifting ~ smooth')

CONTAINS('shifting NEAR smooth')

and 将找到单词 shift 和 smooth 彼此靠近的匹配项.

and will find matches where the words shifting and smooth are near each other.

这篇关于转义括号 [ 在 CONTAINS() 子句中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)