Escaping Bracket [ in a CONTAINS() clause?
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') CONTAINS(crev.RawText, 'arg[]') 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.
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"')
This also works:
CONTAINS('"word1" and "word2" and "word3"')
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"')
and it would find matches for the word shifting that also had the phrase "on or off-road".
The only special symbol is the ~, it can be used in place of the NEAR command.
CONTAINS('shifting ~ smooth')
is the same as
CONTAINS('shifting NEAR smooth')
and will find matches where the words shifting and smooth are near each other.