Improve your stores search by using the product keywords !

Improve CS search capability by searching the products keywords

and meta description if required.





Edit : line 131 of /include/common/search_products.php




foreach ($pieces as $piece) {
$tmp = array();

[COLOR=red]// SWS MOD TO SEARCH PRODUCT KEYWORDS AND META DESCRIPTION
$tmp[] = "descr1.meta_keywords LIKE '%$piece%'";
$tmp[] = "descr1.meta_description LIKE '%$piece%'";
// END SWS MOD HERE [/COLOR]

if ($search_data['search_product_name'] == 'Y') {
$tmp[] = "descr1.product LIKE '%$piece%'";
}

}






Above that code (approx line 115) I couldnt find in the admin where to change this so I modified the code…




[COLOR="Red"]// SWS MOD TO FORCE ALL SEARCH !
$search_data['match'] = 'all' ;
// SWS MOD[/COLOR]
if (!empty($search_string)) {

if ($search_data['match'] == 'any') {
$pieces = explode(' ', $search_string);
$search_type = ' OR ';
} elseif ($search_data['match'] == 'all') {
$pieces = explode(' ', $search_string);
$search_type = ' AND ';
} else {

$pieces = array($search_string);
$search_type = 'OR';
}




Still needs improving but its a start, changing it to OR will give more results, but less specific to the users search.

Ive had another play around to improve the search, so far Ive come up with an ugly hack but its still better than showing the “no products found” message



Basically I have cloned the following file



/includes/common/search_products.php

to

/includes/common/search_products2.php



In the first file, I have set the match type to All




// SWS MOD TO FORCE ALL SEARCH !
$search_data['match'] = 'all' ;
// SWS MOD
if (!empty($search_string)) {

if ($search_data['match'] == 'any') {
$pieces = explode(' ', $search_string);
$search_type = ' OR ';
} elseif ($search_data['match'] == 'all') {
$pieces = explode(' ', $search_string);
$search_type = ' AND ';
} else {

$pieces = array($search_string);
$search_type = 'OR';
}






then in the second file, I have set it to ‘any’ as per code above but changing search type.



Finally I have editted /include/common/search_products_generic.php



and near the bottom changed this code (just below $product_count = …)





if ($product_count == 0 && !defined('SEARCH_PERFORMED')) {
define('SEARCH_PERFORMED', true);

include $common_dir . 'search_products2.php' ;

} else {
$products_per_page = !empty($products_per_page) ? $products_per_page : $settings['Appearance']['admin_products_per_page'];
$limit = fn_paginate($page, $product_count, $products_per_page);
$products = db_get_array("SELECT $fields FROM $db_tables[products] as products $join WHERE $search_condition GROUP BY products.product_id $sorting $limit");
$smarty->assign('search_data', $search_data);
}
/** /Body **/
?>







Im still on a mission to improve searching for my customers, but this certainly helps a lot.

Basically, if nothing is found, it performs a second more relaxed search, if nothing is found a second time around it shows nothing found.



Its not an ideal solution, I know, but the search isnt too hot in CS at the moment, im sure it will be soon though :wink:

Awesome SWS! This is one of the improvements I wanted to see in CS-Cart! YAY =DD Thanks.



BTW would it be at all possible to implement search operators like “” (phrases), - (exclusions) and + (additions)?

Anythings possible, however to be honest it may be worth waiting for their next release to see what they have up their sleeve first.



Search was annoying a little, but then its not just CS cart which suffers from this, a lot of things do. Also using operators for searching isnt common knowledge for the general public

I did your first hack and it works great. I’ve put a helpdesk ticket in. Search is the number one priority of any shopping cart.

Glad to hear you like it and find it useful.

Thanks for the hack. The last one is confusing. Can you explain the generic changes a little more detailed? Thanks

[quote name=‘SWS’]Improve CS search capability by searching the products keywords

and meta description if required.





Edit : line 131 of /include/common/search_products.php




foreach ($pieces as $piece) {
$tmp = array();

[COLOR=red]// SWS MOD TO SEARCH PRODUCT KEYWORDS AND META DESCRIPTION
$tmp[] = "descr1.meta_keywords LIKE '%$piece%'";
$tmp[] = "descr1.meta_description LIKE '%$piece%'";
// END SWS MOD HERE [/COLOR]

if ($search_data['search_product_name'] == 'Y') {
$tmp[] = "descr1.product LIKE '%$piece%'";
}

}






This the modified code… please suggest us that it has been done correctly



foreach ($pieces as $piece) {
$tmp = array();
if ($search_data['search_product_name'] == 'Y') {
$tmp[] = "descr1.product LIKE '%$piece%'";
}
if ($search_data['search_short_description'] == 'Y') {
$tmp[] = "descr1.short_description LIKE '%$piece%'";
}
if ($search_data['search_full_description'] == 'Y') {
$tmp[] = "descr1.full_description LIKE '%$piece%'";
}
if ($search_data['search_meta_keywords'] == 'Y') {
$tmp[] = "descr1.meta_keywords LIKE '%$piece%'";
}
if ($search_data['search_meta_description'] == 'Y') {
$tmp[] = "descr1.meta_description LIKE '%$piece%'";
}
if (is_array($search_data['search_product_features']) && $action != 'feature_search') {
$tmp[] = "$db_tables[product_features_values].value LIKE '%$piece%'";
}

[quote name=‘smavtron’]





foreach ($pieces as $piece) {
$tmp = array();
if ($search_data['search_product_name'] == 'Y') {
$tmp[] = "descr1.product LIKE '%$piece%'";
}
if ($search_data['search_short_description'] == 'Y') {
$tmp[] = "descr1.short_description LIKE '%$piece%'";
}
if ($search_data['search_full_description'] == 'Y') {
$tmp[] = "descr1.full_description LIKE '%$piece%'";
}
if ($search_data['search_meta_keywords'] == 'Y') {
$tmp[] = "descr1.meta_keywords LIKE '%$piece%'";
}
if ($search_data['search_meta_description'] == 'Y') {
$tmp[] = "descr1.meta_description LIKE '%$piece%'";
}
if (is_array($search_data['search_product_features']) && $action != 'feature_search') {
$tmp[] = "$db_tables[product_features_values].value LIKE '%$piece%'";
}
[/QUOTE]





There is no


$search_data['search_meta_description'] == 'Y'



so the best way to do it is to replace


if ($search_data['search_meta_keywords'] == 'Y') {
$tmp[] = "descr1.meta_keywords LIKE '%$piece%'";
}
if ($search_data['search_meta_description'] == 'Y') {
$tmp[] = "descr1.meta_description LIKE '%$piece%'";
}





if ($search_data['search_type'] == 'extended') {
$tmp[] = "descr1.meta_keywords LIKE '%$piece%'";
$tmp[] = "descr1.meta_description LIKE '%$piece%'";
}






Alexandros

It looks like the code for the search_products.php has been updated since 1.3.5.



Or maybe i’m blind.



Will this mod still work? I really just want to add the “Product_Code” field into the default search query so that it searches that field as well.



Thanks

In 1.3.5 there is a new field called Search Words.



It’s nice to know CS-Cart listens to their customers :slight_smile:

Marc,

I am in the process of upgrading to 1.3.5.sp3 and noticed the “Search Words” field also.

Forgive me but what would the difference be between the meta keywords and these “search words”?

I added a couple of “search words” to a product listing but can’t find them in the page source after that. Not sure how search engines would find it?

Thanks,

Eric

Eric-



The Search Words field is used to specify additional words that will be included when using CS-Cart’s product search.



One example would be including a frequent misspelling in the Search Words field. For example, you sell dust ruffles but you might also see that people often incorrectly type “ruffel” when doing a search. You could include “ruffel” in the Search Words for all your dust ruffle products and then all those products would be displayed even when your customer misspelled that word. You could also use it for abbreviations or “aliases” used to refer to your product.



You can find the search words your customers are using in Admin->Statistics:Product Search.



Bob