【问题标题】:How to search phrase with soundex using 1 word?如何使用 1 个单词使用 soundex 搜索短语?
【发布时间】:2023-01-11 12:56:17
【问题描述】:

如果用户在输入中只输入了一个单词时出错,我需要用这个词“table”或“table”或“tables”找到这个短语“small side table”。

我尝试了 MATCH AGAINST 和 LIKE '%%',但是模拟错误写入,它没有找到任何东西,要更正它我需要整个句子 soundex('small side tablr'),但我只有 'tables' 可以搜索


$search="tables";

$data = $connection->query("SELECT title from `posts` where soundex(`title`) = soundex('$search') ");

【问题讨论】:

    标签: php mysql


    【解决方案1】:

    我建议你应该尝试使用 MySQL 的正则表达式函数来搜索文本。 https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-instr

    在您的特定情况下(找到短语“small side table”),查询可能类似于

    SELECT REGEXP_LIKE('small side table', '.*tabl.{1,2}');
    
    SELECT REGEXP_LIKE('small side tablr', '.*tabl.{1,2}');
    
    SELECT REGEXP_LIKE('small side tables', '.*tabl.{1,2}');
    
    SELECT REGEXP_LIKE('small side tablrs', '.*tabl.{1,2}');
    

    你可以在这里试试 https://onecompiler.com/mysql/3yujc3mqx

    当然,您应该修改搜索参数以满足您的需要(如果您之前没有使用过正则表达式,也可以学习一点正则表达式https://regexone.com/)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-20
      • 1970-01-01
      相关资源
      最近更新 更多