Since the thread title is Improving Search Results perhaps this warrants a mention:
https://github.com/lat9/prioritize_matching_names
Since the thread title is Improving Search Results perhaps this warrants a mention:
https://github.com/lat9/prioritize_matching_names
Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...
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; }
Hi @jadebox, I just tried your modified code in zc1.58. Unfortunately, it doesn't make any difference on my search result (not work). Actually the original code from github doesn't make any difference neither. Not sure why...I have changed "header_php.php" file back to the default before the test. No log file is received during my test. The original code is based on zc 1.53 though.
For your mentioned code, I suspected you want to rank by the product name at first, then product description, correct? So your following line below
$in_name_select2 .= "pd.products_name LIKE '%:keywords%'";
It should be changed to the following, if I'm correct.
$in_name_select2 .= "pd.products_description LIKE '%:keywords%'";
It doesn't work no matter I changed the line above or not...
Last edited by njcyx; 9 Nov 2022 at 07:01 PM.
No, I wanted it to sort products that have names that start with the keywords before products that just have the keyword in the name. The first "like" returns True for product names starting with the keywords (:keyword%). The second returns True for product names which include the keywords anywhere (%: keywords%). Using "DESC" causes tbe LIKEs that return True to be listed before the ones that are False.
So, if your keyword is "Red" then a product called "Red Rider BB Gun" will be listed before "Daisy Red Rider BB Gun."
Last edited by jadebox; 9 Nov 2022 at 07:30 PM.
I see. Thanks for your explanation.
I changed the related code to the following and it doesn't work neither...I just want the basic keyword match.
Code: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_description LIKE ':keywords'"; $in_name_select2 = $db->bindVars($in_name_select2, ':keywords', $current_keyword, 'noquotestring'); break;
I would recommend going back to the original code from GitHub and getting it to work before trying to change it. I apologize that I haven't tried torvista's code, but I don't see any obvious reason that it wouldn't work. My guess is that you might not have installed the file in the right folder of your store
There's a support thread for the code at:
https://www.zen-cart.com/showthread....Support-Thread
Hi @jadebox, thanks for your suggestion. I will do some tests to make the original code work at first then....
To muddy the waters further, this thread is related, for those with the time to experiment:
https://github.com/zencart/zencart/issues/5369
I think there is certainly scope to use subqueries in this as described in the comments, but I am just not finding the time...
Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...
I recommend looking at Elastic Search for improving the search functionality. We are using it in both zen cart and non-Zen Cart implementations with great success. You can see a zen cart example at redlinestands.com.
Hi @numinix, thanks for your suggestion. Can you please post some links for the Elastic Search? Is there a plug-in for Zen Cart?
I checked your example link and its search function is too slow. It takes me about 7-8s to load, when I hit the "search" button every time. Also, if I search keyword "2 POST LIFT", the first 10 results don't have "2 POST LIFT" in their titles...
Bookmarks