Escaping Bracket [ in a CONTAINS() clause?

后端 未结 2 726
天涯浪人
天涯浪人 2021-02-05 22:52

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.Raw         


        
2条回答
  •  一整个雨季
    2021-02-05 23:29

    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.

提交回复
热议问题