#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    Need help with code for Site Search


    I previously posted this in the MySql category by mistake, however I believe this is actually PHP code.

    Hi, the basic search on my site is too specific.. Meaning it's too exact with word order and phrases.

    For example, if I search Shoes Red it won't show results for Red Shoes.

    If you search for Red Shoe Laces it won't show results for Red Laces (as the word shoe throws off this order). Below is the code that I believe the search box is using. Can anyone tell me how to "loosen" up this search so it's either more broad or so exact word order isn't necessary?

    This is the current code:

    case 'search':
    if (intval($filter) != 0) {
    $filter = JString::strtolower($filter);
    $id = intval($filter);
    $search .= $temp."(a.id = $id OR LOWER(a.ad_headline) LIKE '%".$this->_db->getEscaped($filter,true)."%' OR LOWER(a.ad_text) LIKE '%".$this->_db->getEscaped($filter,true)."%')";
    } else {
    $filter = JString::strtolower($filter);
    $search .= $temp."(LOWER(a.ad_headline) LIKE '%".$this->_db->getEscaped($filter,true)."%' OR LOWER(a.ad_text) LIKE '%".$this->_db->getEscaped($filter,true)."%')";
    }
    break;
    }
    }
    }
    return $search;
    }


    Any ideas here?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0
    *Bump* Anyone?
  4. #3
  5. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7170
    If your ad_headline and ad_text fields are TEXT fields and have a FULLTEXT index on them you can use the MATCH_AGAINST function to have MySQL run a search on it. Whether a MATCH_AGAINST search is better than what you already have is somewhat questionable. I think it will allow fuzzier word order, but by default it won't search for strings less than 4 characters long, so a search for "Red" would return nothing.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0
    Sounds great.. Yeah I don't expect anyone to use only a 3 letter search word very often at all.. So would this eliminate exact word order requirment then and pull in more results this way if there is a keyword match? What do you mean exactly by being fuzzier?

    Can you show me where in this code to add this MATCH_AGAINST wording?
    Last edited by scottie35s; February 6th, 2013 at 09:00 PM. Reason: corrected to MATCH_AGAINST

IMN logo majestic logo threadwatch logo seochat tools logo