all groups > sql server full text search > april 2006 >
You're in the

sql server full text search

group:

How to use CONTAINS to search words partially?



How to use CONTAINS to search words partially? redhotsly NO[at]SPAM hotmail.com
4/21/2006 12:20:58 PM
sql server full text search: Hi,

Given the following table

Table : Computer
ID Name Notes
1 03-computer01 This webserver (ws) uses a SQL server
2 cls0001NTS5 Is connected to ws03sql001
3 ws03sql001
4 ws03sql002
5 ws03sql003
3 sql-ws03

and knowing that the Name and Note columns have been Indexed in a Full
Text Catalog.

How do I write a SELECT statement to return all the rows containing
"ws" AND "sql". With the data I've given, all the rows should be
returned.

This statement does not work because it seems like there is no way to
search inside the "words" of the index.

SELECT *
FROM computers
WHERE CONTAINS( Computer.*, '"ws" AND "sql"' )

I tried adding * before/after each words but it does not work.

Another solution would be to use a LIKE but it would have a serious
performance impact.

SELECT *
FROM computers
WHERE
( Computer.Name like ('%ws%' ) AND
Computer.Name like ('%sqk%' ) ) OR
( Computer.Note like ('%ws%' ) AND
Computer.Note like ('%sqk%' ) )


I cannot use the LIKE solution because in our case there are more
columns involved and it would be really slow.

Any help will be greatly appreciated.

Thank you

Sylvain
Re: How to use CONTAINS to search words partially? Hilary Cotter
4/21/2006 3:45:14 PM
You will have to add white space in your content before and after the tokens
for this to work. Otherwise this is the best way to do it.

--
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.

This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.

Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html

Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com



[quoted text, click to view]

AddThis Social Bookmark Button