From 2d9e56ca5f29c9dc1e295f534d1be18ed11df9a7 Mon Sep 17 00:00:00 2001 From: Lester Caine Date: Wed, 20 May 2026 16:25:58 +0100 Subject: Fix And Terms Together search for Firebird and PHP namespaces - ORDER BY relevancy/hits by name instead of position 9/5; position 9 resolved to lc.data (BLOB) in find_with_and due to extra hash_key column, causing Firebird to error on BLOB sort - Qualify i_count with table alias to avoid ambiguity - Replace string callback 'search_relevance_sort' with closure; string callbacks resolve in global namespace but function is in Bitweaver\Search - Remove now-redundant standalone search_relevance_sort function Co-Authored-By: Claude Sonnet 4.6 --- includes/classes/SearchLib.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/includes/classes/SearchLib.php b/includes/classes/SearchLib.php index ae0c403..821443d 100755 --- a/includes/classes/SearchLib.php +++ b/includes/classes/SearchLib.php @@ -243,8 +243,8 @@ class SearchLib extends BitBase { LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content_hits` lch ON (lc.`content_id` = lch.`content_id`) $joinSql INNER JOIN `".BIT_DB_PREFIX."search_index` si ON (si.`content_id`=lc.`content_id` AND si.`searchword` = ? ) - WHERE `i_count` > 0 $whereSql - ORDER BY 9 DESC, 5 DESC + WHERE si.`i_count` > 0 $whereSql + ORDER BY relevancy DESC, hits DESC "; $bindVars[0] = $word; $result = $this->mDb->getAssoc( $query, $bindVars ); @@ -260,7 +260,10 @@ class SearchLib extends BitBase { $pParamHash['cant'] = count($ret); /* Sort it */ - uasort($ret, 'search_relevance_sort'); + uasort($ret, function($a, $b) { + $rel = $b['relevancy'] - $a['relevancy']; + return $rel == 0 ? $b['hits'] - $a['hits'] : $rel; + }); /* slice it */ $ret = array_slice($ret, $pParamHash['offset'], $pParamHash['offset'] + $pParamHash['max_records']); @@ -332,12 +335,3 @@ class SearchLib extends BitBase { } # class SearchLib -if (!defined('search_relevance_sort')) { - function search_relevance_sort($a, $b) { - $rel = $b['relevancy'] - $a['relevancy']; - if ($rel == 0) { - $rel = $b['hits'] - $a['hits']; - } - return $rel; - } -} \ No newline at end of file -- cgit v1.3