Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Search functionality seems crippled. Can it be fixed?


yvan

Recommended Posts

Good afternoon. I'm trying to troubleshoot an issue with the search engine within oscommerce, and am stumped as to what might be going on. A full explanation of the issue can be found on the experts exchange website:

 

http://www.experts-exchange.com/Web_Develo...Q_23172114.html

 

Here, however, is a brief summary of the issue:

 

Take a look at this example product name:

 

HP26 51626A Remanufactured Black Cartridge - (HP 26)

 

Notice how it contains both "HP26" -- AND -- "HP 26" ? Why is the "HP 26" string that's within the parentheses being ignored? (when I do a search for "HP 26" -- this specific product is NOT returned as part of the search results)

 

I thought maybe the parentheses might be interfering, so I tried modifying the product name (I removed the parentheses) and then tried doing a search again, ... but the item still isn't being picked up, and isn't displayed in the search results.

 

I CAN, however, return this specific product when I do searches using the following:

 

"HP26"

"HP26 51626A"

"(HP 26)"

"HP26 51626A Remanufactured Black Cartridge - (HP 26)"

 

It's important that this item is returned in search results when people search for "HP 26" -- since often times folks aren't certain is the space is necessary or not, and will sometimes include it.

 

Please advise.

 

Thanks!

- Yvan

Link to comment
Share on other sites

Hi Yvan, yea the default search didn't do what i wanted either,

 

In, catalog/advanced_search_result.php look for the following bit of 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]);

 

JUST BELOW, check that your code is similar to mine,

 

$where_str .= "(pd.products_description like '%" . tep_db_input($keyword) . "%' or pd.products_name like '%" . tep_db_input($keyword) . "%' or m.manufacturers_name like '%" . tep_db_input($keyword) . "%'";

 

that bit of code tells the shop to look through your products_description and products_name and manufacturers_name for anything like $keyword

 

:-" You can even add products_model

 

Good Luck :thumbsup:

Riaan

 

Good afternoon. I'm trying to troubleshoot an issue with the search engine within oscommerce, and am stumped as to what might be going on. A full explanation of the issue can be found on the experts exchange website:

 

http://www.experts-exchange.com/Web_Develo...Q_23172114.html

 

Here, however, is a brief summary of the issue:

 

Take a look at this example product name:

 

HP26 51626A Remanufactured Black Cartridge - (HP 26)

 

Notice how it contains both "HP26" -- AND -- "HP 26" ? Why is the "HP 26" string that's within the parentheses being ignored? (when I do a search for "HP 26" -- this specific product is NOT returned as part of the search results)

 

I thought maybe the parentheses might be interfering, so I tried modifying the product name (I removed the parentheses) and then tried doing a search again, ... but the item still isn't being picked up, and isn't displayed in the search results.

 

I CAN, however, return this specific product when I do searches using the following:

 

"HP26"

"HP26 51626A"

"(HP 26)"

"HP26 51626A Remanufactured Black Cartridge - (HP 26)"

 

It's important that this item is returned in search results when people search for "HP 26" -- since often times folks aren't certain is the space is necessary or not, and will sometimes include it.

 

Please advise.

 

Thanks!

- Yvan

I'm an osCommerce Pimp ..

Link to comment
Share on other sites

Riaan -- I've tried as you've suggested, ... but I now get the following error message when I try to do searches:

 

1064 - You have an error in your SQL syntax near 'pd.products_description like '%26%' or pd.products_name like '%26%' or m.manufac' at line 1

 

select count(distinct p.products_id) as total from products p left join manufacturers m using(manufacturers_id), products_description pd left join specials s on p.products_id = s.products_id, categories c, products_to_categories p2c where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '1' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and ((pd.products_name like '%hp%' or p.products_model like '%hp%' or m.manufacturers_name like '%hp%') and (pd.products_name like '%26%' or p.products_model like '%26%' or m.manufacturers_name like '%26%')pd.products_description like '%26%' or pd.products_name like '%26%' or m.manufacturers_name like '%26%'

 

[TEP STOP]

 

Here is the exact code that I have in place (thanks in advance) :

 

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

     $where_str .= "(pd.products_description like '%" . tep_db_input($keyword) . "%' or pd.products_name like '%" . tep_db_input($keyword) . "%' or m.manufacturers_name like '%" . tep_db_input($keyword) . "%'";
 }

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...