Search code examples
asp.netsql-serverfull-text-search

How do I handle an apostrophe (') in MS SQL 2008 FTS?


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


Solution

  • 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/