Use SOUNDEX() word by word on SQL Server

前端 未结 5 1634
青春惊慌失措
青春惊慌失措 2020-12-31 23:59

Here is my problem. For example I have a table Products that contains a field, Name:

Products
ID | Name | ..
1  | \"USB Key 10Go\"
2  | \"I         


        
5条回答
  •  一个人的身影
    2021-01-01 00:06

    You could try storing the metaphone of each word concatenated with hyphens. EG stored_metaphone field could contain something like '-AKTRF-SPLS-'. Then build a query like this:

    $where = '(';
    $search_sql = array();
    $search_terms = explode(' ',$search);
    foreach ($search_terms as $term) {
        $search_sql[] = "`stored_metaphone` LIKE '%-".metaphone($term)."-%'";
    }
    $where .= implode(' OR ',$search_sql);
    $where .= ')';
    

    NB this is only the WHERE part of the query.

    As far as I know metaphone only works with English. The above sql is working rather well on a number of sites.

提交回复
热议问题