
Originally Posted by
torvista
That's a good update since it makes products with the search keywords in the product name appear before ones just matching words in the description. A slight enhancement would be to have product names that begin with the keywords listed first. I haven't tested it, but something like the following might work:
Code:
public function update(&$class, $eventID)
{
switch ($eventID) {
case 'NOTIFY_SEARCH_SELECT_STRING':
global $db, $keywords, $select_str;
if (!empty($keywords) && zen_parse_search_string(stripslashes($_GET['keyword']), $search_keywords)) {
$in_name_select1 = '';
$in_name_select2 = '';
foreach ($search_keywords as $current_keyword) {
switch ($current_keyword) {
case '(':
case ')':
case 'and':
case 'or':
$in_name_select1 .= " $current_keyword ";
$in_name_select2 .= " $current_keyword ";
break;
default:
$in_name_select1 .= "pd.products_name LIKE '%:keywords'";
$in_name_select1 = $db->bindVars($in_name_select1, ':keywords', $current_keyword, 'noquotestring');
$in_name_select2 .= "pd.products_name LIKE '%:keywords%'";
$in_name_select2 = $db->bindVars($in_name_select2, ':keywords', $current_keyword, 'noquotestring');
break;
}
}
$select_str .= ", IF ($in_name_select1, 1, 0) AS in_name1, IF ($in_name_select2, 1, 0) AS in_name2 ";
$this->order_by = ' in_name1 DESC, in_name2 DESC,';
}
break;
case 'NOTIFY_SEARCH_ORDERBY_STRING':
global $listing_sql;
$listing_sql = str_ireplace('order by', 'order by' . $this->order_by, $listing_sql);
break;
default:
break;
}