Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Search Bug?


FlyingMonkey

Recommended Posts

When using the search functionality of osC, it does not perform as expected. For instance:

 

If I type in:

table

 

It returns products with descriptions that include:

portable

Adjustable

 

After reading the osC search help (popup_search_help.php)

Keywords may be separated by AND and/or OR statements for greater control of the search results.

 

For example, Microsoft AND mouse would generate a result set that contain both words. However, for mouse OR keyboard, the result set returned would contain both or either words.

 

Exact matches can be searched for by enclosing keywords in double-quotes.

 

For example, "notebook computer" would generate a result set which match the exact string.

 

Brackets can be used for further control on the result set.

 

For example, Microsoft and (keyboard or mouse or "visual basic")

 

Searching for:

"table"

Should return results with only the whole word table. However, it does not return any results at all for me. (Yes, I have products with just the word "table" :) ).

 

Is anyone else having this problem? and is there a fix?

 

Thanks in advance.

Most likely your question has been answered, please do a search first.

Link to comment
Share on other sites

This occurs also in the osC demonstration store.

 

http://demo.oscommerce.com/advanced_search...n_description=1

 

Will provide results with products descriptions such as swords or word.

 

However, when an exact search is ran:

 

for "swords", no results are found. Even for phrases, this is true.

http://demo.oscommerce.com/advanced_search...n_description=1

 

 

 

http://demo.oscommerce.com/advanced_search.php

Don't forget to click search descriptions.

 

Thanks.

Most likely your question has been answered, please do a search first.

Link to comment
Share on other sites

Found a Fix! Hans Wolf's one post wonder.

 

http://www.oscommerce.com/forums/index.php?sho...mp;#entry411609

 

 

I had the same issue, and came up with a hack that works for me. Mine is a bit modified to work with the extra fields contribution, but otherwise you should be able to get it working. This is from around line 257 from advanced_search_results.php. Please post if this works for you, or what you did to make it better!

if (isset($search_keywords) && (sizeof($search_keywords) > 0)) {
$where_str .= " and (";
for ($i=0, $n=sizeof($search_keywords); $i<$n; $i++ ) {

// Hans Wolff - attempt to add quote support
if ( substr_count($search_keywords[$i], '"') == 1) {
if (!$quoteflag) {
$keyword = $search_keywords[$i] . ' ';
$quoteflag = 1;
} else {
$keyword .= $search_keywords[$i];
$quoteflag = 0;
$multi = 1;
}
}
if ( substr_count($search_keywords[$i], '"') > 1 ) {
$keyword = $search_keywords[$i];
}

switch ($search_keywords[$i]) {
case '(': 
case ')': 
case 'and':
case 'or':
if (!$quoteflag && !$multi) $where_str .= " " . $search_keywords[$i] . " ";
break;
default:
if ($quoteflag) break;
if (!$multi) $keyword = tep_db_prepare_input($search_keywords[$i]);
$keyword = trim($keyword, '\"');
// START: Extra Fields Contribution
$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) . "%'";
$where_str .= " or p2pef.products_extra_fields_value like '%" . tep_db_input($keyword) . "%'";
// END: Extra Fields Contribution
$where_str .= " or pd.products_description like '%" . tep_db_input($keyword) . "%'";
$where_str .= ')';
$keyword = '';
$multi = '';
break;
}
}
$where_str .= " )";
}

Most likely your question has been answered, please do a search first.

Link to comment
Share on other sites

I can't address the first part, why it's picking up 'portable' when searching for table...that's screwy.

 

But, as far as searching with quotation marks goes...the default install of OSC does not accomodate such.

 

You'll have to go into catalog/advanced_search_results.php and very near the top, look for this chunk of code:

 

if (isset($HTTP_GET_VARS['keywords'])) {
$keywords = $HTTP_GET_VARS['keywords'];
}

 

Add the word stripslashes so it now looks like this:

 

if (isset($HTTP_GET_VARS['keywords'])) {
$keywords = stripslashes($HTTP_GET_VARS['keywords']);
}

 

That will enable you to search with quotation marks around your keywords. But, it will not work if you're only using one word, like "table". You will continue to get zero search results if using only one keyword surrounded by quotes. I don't know why that is, but the quotation marks will work if they are around two or more keywords, like..."blue table", something like that. Hope that helps!

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...