dr9379 2011-12-06 01:59
浏览 51

可能使用Levenshtein距离匹配搜索词的准确性

i have a mySQL table where people add their names and their interests. I want to use some sort of word match that goes through and finds either a 100% match or a close match. Ive heard of the levenshtein distance but have no clue how to make it cycle through my table.

    $input = $_POST["interest"];
    $result = mysql_query("SELECT interest_desc FROM interests");

Done some googling and got to this point

   function closest($seed, $haystack){
   $shortest = -1;
     foreach ($haystack as $word){
      $lev = levenshtein($seed, $word);
       if ($lev == 0) {
           $closest = $word; $shortest = 0; break;
       }
       if ($lev <= $shortest || $shortest < 0) {
       $closest  = $word; $shortest = $lev;
       }
}
return $closest;
}
$array = mysql_fetch_row($result);
$closestmatch = closest($input,$array);
echo $closetmatch;
  • 写回答

2条回答 默认 最新

  • dphj737575 2014-03-04 21:05
    关注

    I think SOUNDEX is an alternative for you.

    The Lo Sauer's article can help you with that

    http://www.lsauer.com/2013/05/mysql-fuzzy-searching-fulltext-queries.html

    评论

报告相同问题?

悬赏问题

  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作