views:

311

answers:

1

Hi,

I have a website that utilizes MS SQL 2008's FTS (Full-Text Search). The search works fine if the user searches for a string with an apostrophe like that's - it returns any results that contain that's. However, it will not return a result if the user searches for thats, and the database stores that's.

Also, ideally a search for that's should also return thats and that, etc.

Anybody know if FTS supports this, and what I can do to enable it?

WT

+1  A: 

use a parameter

myCommand.Parameters.AddWithValue("@searchterm", txtSearch.Text.Trim());

it will be handle by you, without any hassle.

regarding that, that's and thats you should look up SOUNDEX keyword. 4GuysfromRolla have an old article about it as well.

updated there is a great talk from one of the TFS Team member regarding this here.

quoting him:

Daniel is correct Full-text Search (FTS) does not use SOUNDEX directly, but it can be used in combination with SOUNDEX.
Additionally, you may want to review the following links as well as the below TSQL examples of combining CONTAINS & SOUNDEX

You may want to look at some of the improved soundex algorithms as well as the Levenshtein Distance algorithm
You should be able to search Google to find more code examples, for example: 'METAPHONE soundex "sql server" fuzzy name search' and I quickly found - "Double Metaphone Sounds Great" at http://www.winnetmag.com/Article/ArticleID/26094/26094.html

You can freely download the code in a zip file that has several a user-defined function (UDF) that implement Double Metaphone.

Below are some additional SOUNDEX links:
http://www.merriampark.com/ld.htm
http://www.bcs-mt.org.uk/nala_006.htm

(omitted for out of scoop)

use pubs     

-- Combined SOUNDEX OR CONTAINS query that 
-- Searches for names that sound like "Michael".      
SELECT 
    au_lname, au_fname 
FROM 
    authors -- returns 2 rows      
WHERE 
    contains(au_fname, 'Mich*') or SOUNDEX(au_fname) = 'M240'

Thanks,
John
SQL Full Text Search Blog
http://spaces.msn.com/members/jtkane/

balexandre
Hi, thanks for the links. I didn't understand the part about parameters - I am using a SP which I am already passing values to. Is this what you meant?
Wild Thing
Yes. You could be using inline SQL and were struggling about the single quote char, but using parameters like I show, all special chars will be passed correctly. - Added more content regarding SOUNDEX and FTS -
balexandre
Ok, thanks - I was immediately able to solve the problem using DIFFERENCE, which is a variant of SOUNDEX! Brilliant! Thanks! Will also read the links you've sent, in case there's something I should be careful about...
Wild Thing
glad to help :)
balexandre
SOUNDEX is an i18n disaster waiting to happen.
MSalters
MSalters, that's fine - we're targeting only one language.
Wild Thing