Results 1 to 3 of 3

Search Problem

This is a discussion on Search Problem within the osCommerce 2.2 Modification Help forums, part of the osCommerce 2.2 Forums category; I was wondering if anyone could help me out with this problem. Here it is... When I search for an ...

      
  1. #1
    Member andyy15's Avatar
    Join Date
    Aug 2004
    Posts
    63
    Rep Power
    0


    Default Search Problem

    I was wondering if anyone could help me out with this problem. Here it is... When I search for an item say I enter "rings" the search turns up both "earrings" and "rings". I only want the search to turn up rings and not display earrings. Does anyone know how to fix this search algorithm problem? I have isolated it to this code:
    Code:
     if (isset($search_keywords) && (sizeof($search_keywords) > 0)) {
       $where_str .= " and (";
       for ($i=0, $n=sizeof($search_keywords); $i<$n; $i++ ) {
         switch ($search_keywords[$i]) {
           case '(':
           case ')':
           case 'and':
           case 'or':
             $where_str .= " " . $search_keywords[$i] . " ";
             break;
           default:
             $keyword = tep_db_prepare_input($search_keywords[$i]);
             $where_str .= "(pd.products_name like '%" . tep_db_input($keyword) . "%' or p.products_model like '%" . tep_db_input($keyword) . "%' or m.manufacturers_name like '%" . tep_db_input($keyword) . "%'";
             if (isset($HTTP_GET_VARS['search_in_description']) && ($HTTP_GET_VARS['search_in_description'] == '1')) $where_str .= " or pd.products_description like '%" . tep_db_input($keyword) . "%'";
             $where_str .= ')';
             break;
         }
       }
       $where_str .= " )";
     }
    Thanks,
    Andrew

  2. #2
    Lurker
    Join Date
    Jan 2007
    Posts
    2
    Rep Power
    0


    Wink Re: Search Problem

    Just take out the %'s in the following lines:

    $where_str .= "(pd.products_name like '%" . tep_db_input($keyword) . "%' or p.products_model like '%" . tep_db_input($keyword) . "%' or m.manufacturers_name like '%" . tep_db_input($keyword) . "%'";
    if (isset($HTTP_GET_VARS['search_in_description']) && ($HTTP_GET_VARS['search_in_description'] == '1')) $where_str .= " or pd.products_description like '%" . tep_db_input($keyword) . "%'";
    $where_str .= ')';

    to read:

    $where_str .= "(pd.products_name like '" . tep_db_input($keyword) . "' or p.products_model like '" . tep_db_input($keyword) . "' or m.manufacturers_name like '" . tep_db_input($keyword) . "'";
    if (isset($HTTP_GET_VARS['search_in_description']) && ($HTTP_GET_VARS['search_in_description'] == '1')) $where_str .= " or pd.products_description like '" . tep_db_input($keyword) . "'";
    $where_str .= ')';

    The % is a SQL wildcard character. If you searched for "rings" with the new script... you'll get "rings".

    Robbie Smith
    Azurite Design
    Azurite Design - Sarasota and Bradenton Web Sites
    O: 941-580-3452
    C: 941-735-5592

  3. #3
    Lurker
    Join Date
    Jan 2007
    Posts
    2
    Rep Power
    0


    Talking Re: Search Problem

    My bad. the keyword LIKE is used in tandom with the %'s. If you take out the %'s, then the LIKE needs to be a '=' to get exact matches.

Similar Threads

  1. problem with admin panel search function
    By taol in forum osCMax v2 Features Discussion
    Replies: 0
    Last Post: 12-13-2006, 04:15 PM
  2. How to have Quick Search also search in Descriptions
    By ozstar in forum osCommerce 2.2 Modification Help
    Replies: 1
    Last Post: 12-09-2005, 12:45 PM
  3. Full text search in advanced search
    By Anonymous in forum osCmax v1.7 Discussion
    Replies: 0
    Last Post: 04-15-2004, 03:00 PM
  4. Search Engine Submission Problem
    By OyedeleG in forum osCmax v1.7 Discussion
    Replies: 0
    Last Post: 11-22-2003, 06:45 PM
  5. How to make search box also search descriptions
    By marco6090 in forum osCommerce 2.2 Modification Help
    Replies: 0
    Last Post: 01-06-2003, 05:31 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •