Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full text search syntax error

I created a full text search with a catalog and index and the contains query works fine when I run a query with one word like below.

SELECT Name
FROM dbo.Gifts
WHERE CONTAINS(Name, 'gift')

it returns 'test gift'

I have only one row in the table and the data in the Name column looks like this: 'test gift'

but when I run the conaints query with this statement:

SELECT Name
FROM dbo.Gifts
WHERE CONTAINS(Name, 'test gift')

It throws an error saying: Syntax error near 'gift' in the full-text search condition 'test gift'.

I thought contains could query phrases and multiple words that match and sound alike?

like image 443
user1186050 Avatar asked Dec 14 '25 07:12

user1186050


1 Answers

You need double quotes to manage that space, keeping in mind that you are searching for the entire string, and not the words of the string. The following query would find "test gift" but not "gift test"

SELECT Name
FROM dbo.Gifts
WHERE CONTAINS(Name, '"test gift"')

or, if you want to search words individually, it would be

SELECT Name
FROM dbo.Gifts
WHERE CONTAINS(Name, '"test" AND "gift"')

this second one should get you a field with "gift test" as well as "test gift"

like image 138
Ryan B. Avatar answered Dec 16 '25 22:12

Ryan B.