Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Searching for Exact matches, with quotes


zinkatres

Recommended Posts

Hello,

 

I am trying to make my store advanced search work to find exact matches.

 

As it stands now, if you search for something such as: man then you will get everything that contains man (cartman,Germany,many, etc)

 

I would like to make it so if someone searches "man", then they only get and item that contains the word man.

 

another feature (but totally optional) would to make this not case sensitive (ie "man" would get Man, man, MAn, etc...)

 

Please could someone point me in the correct direction of what code to edit / add

 

I am using osC 2.2 M2 and using the defualt advanced_search_result.php file

 

thank you in advance,

Bil

Link to comment
Share on other sites

Hello,

 

I am trying to make my store advanced search work to find exact matches.

 

As it stands now, if you search for something such as: man then you will get everything that contains man (cartman,Germany,many, etc)

 

I would like to make it so if someone searches "man", then they only get and item that contains the word man.

 

another feature (but totally optional) would to make this not case sensitive (ie "man" would get Man, man, MAn, etc...)

 

Please could someone point me in the correct direction of what code to edit / add

 

I am using osC 2.2 M2 and using the defualt advanced_search_result.php file

 

thank you in advance,

Bil

 

normally search works with sql  like '%keyword' and '%keyword%'.

so that also takes partial word matches.

you may change it to like '% keyword' and '% keyword %'

 

see if that helps.

Treasurer MFC

Link to comment
Share on other sites

normally search works with sql  like '%keyword' and '%keyword%'.

so that also takes partial word matches.

you may change it to like '% keyword' and '% keyword %'

 

boxtel, Where would I change this at?

 

 

in advanced_search_result.php

I am looking at the following piece of code where I think it would go

  }

 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 .= " )";
 }

 

Would I apply your advice to this, if so where. If not please let me know where to look

 

thanks again,

bil

Link to comment
Share on other sites

boxtel, Where would I change this at?

in advanced_search_result.php

I am looking at the following piece of code where I think it would go

 ?}

?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 .= " )";
?}

 

Would I apply your advice to this, if so where. If not please let me know where to look

 

thanks again,

bil

 

yes like :

 

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 .= ')';

 

did not test it but you could try.

Treasurer MFC

Link to comment
Share on other sites

yes like :

 

      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 .= ')';

 

did not test it but you could try.

 

Thank you for your quick help. Even though this is not exactly what i wanted (wanted to place quotes around the word to trigger this functionality) This should suffice for my purposes for now.

 

Just one other thought tho, would it be possible to so something like this:

If *entered keywords contain quotes, such as "man", then use your suggested code*
       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;
else *use original code*

 

I have no idea if that situation could even be written like that, but I was a thought I had.

 

Thanks again,

bil

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...