search title first,if come back without result then go to product description search

48 Views Asked by At

I have a zencart website,currently i need customer to search tile first because it will get lots of result if search product description also.SO i change 'search_in_description', to "0",what should i do if i need it search in product description automatically if no result get from title search?

$content = "";
    $content .= zen_draw_form('quick_find_header', zen_href_link(FILENAME_ADVANCED_SEARCH_RESULT, '', $request_type, false), 'get');
    $content .= "<span>Search: </span>";
    $content .= zen_draw_hidden_field('main_page',FILENAME_ADVANCED_SEARCH_RESULT);
    $content .= zen_draw_hidden_field('search_in_description', '0') . zen_hide_session_id();

    if (strtolower(IMAGE_USE_CSS_BUTTONS) == 'yes') {
        $content .= zen_draw_input_field('keyword', '', 'size="6" maxlength="120" class="search-header-box" value="' . HEADER_SEARCH_DEFAULT_TEXT . '" onfocus="if (this.value == \'' . HEADER_SEARCH_DEFAULT_TEXT . '\') this.value = \'\';" onblur="if (this.value == \'\') this.value = \'' . HEADER_SEARCH_DEFAULT_TEXT . '\';"') . '' . zen_image_submit (BUTTON_IMAGE_SEARCH,HEADER_SEARCH_BUTTON);
    } else {
        $content .= zen_draw_input_field('keyword', '', 'size="6" class="search-header-box" maxlength="120" value="' . HEADER_SEARCH_DEFAULT_TEXT . '" onfocus="if (this.value == \'' . HEADER_SEARCH_DEFAULT_TEXT . '\') this.value = \'\';" onblur="if (this.value == \'\') this.value = \'' . HEADER_SEARCH_DEFAULT_TEXT . '\';"');
    }
    $content .= zen_draw_pull_down_menu('categories_id', $categories_array,'','class="select" id="light_select"');
    $content .= "</form>";
?>
2

There are 2 best solutions below

0
Scott C Wilson On

It's not in the template file (what you're showing). The change should be in includes/modules/pages/advanced_search/header_php.php.

Using version 1.5.5e line numbers:

Below line 463

if ($result->number_of_rows == 0) {

You want to rerun the query, but with search in product description enabled.

Here's how I would do that. After the if block from line 330 ends at line 335, I'd put in an extra clause that would never trigger, like:

} else { 
   $where_str .= " OR (1=0)"
}

Then down on line 463, when the original search fails, replace "1=0" with the product description search logic

for ($i=0, $n=sizeof($search_keywords); $i<$n; $i++ ) {
   $new_str .= " OR pd.products_description
                          LIKE '%:keywords%'";

   $new_str .= $db->bindVars($new_str, ':keywords', $search_keywords[$i], 'noquotestring');
}

Then use str_replace to change 1=0 to $new_str and rerun the queryby calling splitPageResults again.

0
bislewl On

I would recommend installing the Reloaded Search Module. Than you can add weight the name, meta tags, etc. If you aren't comfortable with mid-advance level module installations I would find someone to install it for you.