問題描述
如何在全文 SQL Server contains()
查詢中轉(zhuǎn)義括號(hào)?我已經(jīng)嘗試了以下所有方法,沒有有效:
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\]')
使用雙引號(hào)確實(shí)有效,但它強(qiáng)制整個(gè)搜索成為一個(gè)詞組,這是多詞查詢的一個(gè)亮點(diǎn).
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]"')
我真正想做的就是擺脫括號(hào),但我似乎無法做到..
All I really want to do is escape the bracket, but I can't seem to do that..
推薦答案
您不必轉(zhuǎn)義 [,因?yàn)樗谌乃阉髦袥]有特殊含義.但是,如果您確實(shí)需要搜索完全匹配項(xiàng),則可以使用 "" 標(biāo)記.
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.
此外,您可以在單引號(hào)內(nèi)使用多個(gè)":
Further, you can use multiple "" inside the single quotes:
CONTAINS('"word1" or "word2" or "word3"')
這也有效:
CONTAINS('"word1" and "word2" and "word3"')
雙引號(hào)內(nèi)的任何內(nèi)容都被視為精確文本.因此,如果我要搜索 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"')
并且它會(huì)找到與on or off-road"這個(gè)詞組匹配的詞 shift.
and it would find matches for the word shifting that also had the phrase "on or off-road".
唯一的特殊符號(hào)是 ~,它可以用來代替 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 彼此靠近的匹配項(xiàng).
and will find matches where the words shifting and smooth are near each other.
這篇關(guān)于轉(zhuǎn)義括號(hào) [ 在 CONTAINS() 子句中?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!