Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Full-Text Search Syntax

Microsoft's documentation for CONTAINS includes the following two clauses in their examples.

CONTAINS(Name, ' "Mountain" OR "Road" ')

And also...

CONTAINS(Description, ' Aluminum AND spindle ');

Note that the first example places both search terms within double quotes while the second example does not. I cannot seem to find anyplace where it explains what is the difference between the two.

Since neither FORMSOF(INFLECTIONAL, ...) or FORMSOF(THESAURUS, ...) are used, I can only assume that the words are compared literally in both cases. That would mean both versions are equal. So why include them in double quotes in the first example?

like image 637
Jonathan Wood Avatar asked Feb 28 '26 20:02

Jonathan Wood


1 Answers

It is my understanding that quotes are only strictly required when a search phrase contains a wildcard or multiple words. If the search phrase is a single word and does not user a wildcard, then strictly speaking, double-quotes are not required.

CONTAINS(LastName, 'Anders') --double quotes not required
CONTAINS(LastName, '"Anders*"') --double quotes required since wildcard used.  Match Anders, Anderson, etc
CONTAINS(Title,  '"End of time"') --double quotes required, since multiple words

Of course, double quotes can still be used even when they are not required:

CONTAINS(LastName, '"Anders"')

Here is a quote BOL regarding the need for double quotes when a wildcard is used:

If the text and asterisk are not delimited by double quotation marks, so the predicate reads CONTAINS (column, 'text*'), full-text search considers the asterisk as a character and searches for exact matches to text*.>

like image 173
Joe Alfano Avatar answered Mar 03 '26 08:03

Joe Alfano