問題描述
如何在全文 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() 子句中?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!