-- HikaShop version -- : 6.3.0
-- Joomla version -- : 5.4.4
-- PHP version -- : 8.2
-- Browser(s) name and version -- : Google chrome
Hi,
I'm trying to prioritize search results so that products matching the search term in the "product_name" appear before those matching in the
"description" or "keywords".
Currently, when a customer searches for a word that appears in both a product title and another product's description, the description match sometimes shows up first. I'd like to enforce this ordering:
1. Title match → highest priority
2. Description match → medium priority
3. Keywords match → lowest priority
I've been looking at the `onBeforeProductListingLoad(&$filters, &$order, &$view, &$select, &$select2, &$a, &$b, &$on)` event, and my approach is to inject a relevance score into `$select2` using a `CASE WHEN` expression, then override `$order` with that score:
$scoreExpr = "
(
CASE WHEN {$b}.product_name LIKE '%{$term}%' THEN 3 ELSE 0 END
+ CASE WHEN {$b}.product_description LIKE '%{$term}%' THEN 2 ELSE 0 END
+ CASE WHEN {$b}.product_meta_keywords LIKE '%{$term}%' THEN 1 ELSE 0 END
)
";
$select2 .= ', ' . $scoreExpr . ' AS hika_search_score';
$order = ' hika_search_score DESC, ' . $b . '.product_name ASC';
My concern is: does HikaShop override the `$order` variable after this event fires? In other words, is modifying `$order` inside `onBeforeProductListingLoad` guaranteed to affect the final SQL query, or does the core overwrite it later in the execution flow?
If this approach is not reliable, what would be the recommended way to achieve relevance-based search ordering in HikaShop?
Thank you!