1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

problem in search with levenshtein

Discussion in 'PHP' started by vipin8vit, Nov 4, 2008.

  1. #1
    i am trying a search with levenshtein but m stuck with a serious problem.The field "topic" in the database is a string of more than one word which m not able to solve with the type of search i am doing here.had there been one word in the string it would be fine but for such case its a total failure.

    i also need to use the soundex() or some similar function as the entries in my database are no similar.and again one more problem php 4.4.2 that m using is case sensitive so levenshtein is not working fine.

    m totally stuck.please fix the code.here is the code

    // input misspelled word


    $arrWords=explode(" ",$input);

    echo"enter keyword";

    echo"<a href=\"lev.php\">click here</a>";



    $shortest = -1;


    //foreach ($arrWords as $trimm){
    //$query1 = "SELECT topic FROM forum_question WHERE topic LIKE \"%$trimm%\" ORDER BY id DESC" ;

    $query1="select topic from forum_question";

    //echo $topic,"\n";

    //$toopic=explode(" ",$topic);
    //echo $toopic[$i][$k];

    //foreach ($topic as $word) {


    $lev = levenshtein($arrWords[$i], $topic[$j]);


    if ($lev == 0) {

    // closest word is this one (exact match)
    $closest = $topic[$j];
    $shortest = 0;

    // break out of the loop; we've found an exact match

    if ($lev <= $shortest || $shortest < 0) {
    // set the closest match, and shortest distance
    $closest = $topic[$j];
    $shortest = $lev;



    echo "Input word: $arrWords[$i]\n";
    if ($shortest == 0) {
    echo "Exact match found: $closest\n";
    } else {
    echo "Did you mean: $closest?\n";

    vipin8vit, Nov 4, 2008 IP