Search code examples
phpmysqlsoundex

Is there easy way to match word from a database table field with soundex?


Hi Just Before going deep into soundex, wanted to ask quick qiestion.

1 - field in the table[title] contains a "Sentence that has WORD I am looking for"

Q - Is there are easy way to match the WORD using a sundex ?


Solution

  • SOUNDEX is a way to match Smith, Smythe and Smeathe while searching for Smith:

    SELECT  *
    FROM    names
    WHERE   name_soundex = SOUNDEX('Smith')
    
    name     name_soundex
    --
    Smith    S530
    Smythe   S530
    Smeathe  S530
    

    What you need is called FULLTEXT indexing:

    CREATE FULLTEXT INDEX fx_mytable_title ON mytable (title)
    
    SELECT  *
    FROM    mytable
    WHERE   MATCH(title) AGAINST ('+fox')
    
    title
    --
    A quick brown fox jumped over the lazy dog