转义括号 [ 在 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() 子句中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

相关文档推荐

Number of working days between two dates(两个日期之间的工作日数)
How do I use dateadd to get the first day of last year?(如何使用 dateadd 获取去年的第一天?)
SQL- Count occurrences of a specific word within all stored procedures(SQL- 计算所有存储过程中特定单词的出现次数)
SQL query to make a column of numbers a string(使一列数字成为字符串的 SQL 查询)
T-SQL: Best way to replace NULL with most recent non-null value?(T-SQL:用最新的非空值替换 NULL 的最佳方法?)
Count days in date range with set of exclusions which may overlap(使用一组可能重叠的排除项计算日期范围内的天数)