Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full text search in sql server

I am using SQL Server 2008. I have indexed the ProductName column in the Product table as full text search index. Some ProductName values as examples:

ProductName
-------------
Iphone 3GS
Iphone 4S
Iphone 5S
Iphone 5

Now I am using the following code to search for Product:

WHERE CONTAINS (Product.ProductName, '"Iphone 4S"')

It's OK! But if I edit and use this:

WHERE CONTAINS (Product.ProductName, '"4S Iphone"')

No results!

Could you help me to solve this problem? Thanks.

like image 718
Jonny Vu Avatar asked Nov 08 '13 10:11

Jonny Vu


2 Answers

you want find out results which contain Iphone,4S.So you can use OR condition to get the result.

WHERE CONTAINS (Product.ProductName, '4S  OR Iphone')

Following link will be more useful for better understanding. http://blog.sqlauthority.com/2008/09/05/sql-server-creating-full-text-catalog-and-index/

like image 161
MaheshMajeti Avatar answered Oct 04 '22 06:10

MaheshMajeti


Sounds like you'll want to use the NEAR operator between 4S and Iphone. It searches for words with those, and the order can be independent.

WHERE CONTAINS (Product.ProductName, '"4S" NEAR "Iphone"')

You can also use a tilde(~) in place of the NEAR statement

WHERE CONTAINS (Product.ProductName, '"4S" ~ "Iphone"')
like image 43
raykendo Avatar answered Oct 04 '22 05:10

raykendo