diff options
| author | Lester Caine <lester@lsces.co.uk> | 2026-05-14 09:52:56 +0100 |
|---|---|---|
| committer | Lester Caine <lester@lsces.co.uk> | 2026-05-14 09:52:56 +0100 |
| commit | ed7ded38465662eabdd1b16dd9cd4008d6c5528f (patch) | |
| tree | 7c3ebe7246ac47f6b7bbca3419f22be3718892f6 /includes | |
| parent | 758faa3c26c4756874616e87e0433691e8393b6e (diff) | |
| download | search-ed7ded38465662eabdd1b16dd9cd4008d6c5528f.tar.gz search-ed7ded38465662eabdd1b16dd9cd4008d6c5528f.tar.bz2 search-ed7ded38465662eabdd1b16dd9cd4008d6c5528f.zip | |
php-cs-fixer tidies to php8.5 standards
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'includes')
| -rwxr-xr-x | includes/bit_setup_inc.php | 7 | ||||
| -rwxr-xr-x | includes/classes/SearchLib.php | 35 | ||||
| -rwxr-xr-x | includes/classes/SearchStatsLib.php | 1 | ||||
| -rwxr-xr-x | includes/refresh_functions.php | 3 |
4 files changed, 24 insertions, 22 deletions
diff --git a/includes/bit_setup_inc.php b/includes/bit_setup_inc.php index ae4cfed..2c8ad5e 100755 --- a/includes/bit_setup_inc.php +++ b/includes/bit_setup_inc.php @@ -1,5 +1,6 @@ <?php namespace Bitweaver\Search; + global $gBitSystem, $gLibertySystem ; $pRegisterHash = [ @@ -12,9 +13,9 @@ $pRegisterHash = [ define( 'SEARCH_PKG_NAME', $pRegisterHash['package_name'] ); define( 'SEARCH_PKG_URL', BIT_ROOT_URL . basename( $pRegisterHash['package_path'] ) . '/' ); define( 'SEARCH_PKG_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/' ); -define( 'SEARCH_PKG_INCLUDE_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/includes/'); +define( 'SEARCH_PKG_INCLUDE_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/includes/'); define( 'SEARCH_PKG_CLASS_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/includes/classes/'); -define( 'SEARCH_PKG_ADMIN_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/admin/'); +define( 'SEARCH_PKG_ADMIN_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/admin/'); $gBitSystem->registerPackage( $pRegisterHash ); @@ -35,5 +36,5 @@ if( $gBitSystem->isPackageActive( 'search' ) ) { } include_once SEARCH_PKG_INCLUDE_PATH . 'refresh_functions.php'; $gLibertySystem->registerService( LIBERTY_SERVICE_SEARCH, SEARCH_PKG_NAME, - [ 'content_store_function' => 'refresh_index'] ); + [ 'content_store_function' => 'refresh_index'], ); }
\ No newline at end of file diff --git a/includes/classes/SearchLib.php b/includes/classes/SearchLib.php index 024d340..f43a9eb 100755 --- a/includes/classes/SearchLib.php +++ b/includes/classes/SearchLib.php @@ -18,6 +18,7 @@ */ namespace Bitweaver\Search; + use Bitweaver\BitBase; use Bitweaver\Liberty\LibertyBase; @@ -37,7 +38,7 @@ class SearchLib extends BitBase { foreach ($words as $word) { $word = trim($word); $cant = $this->mDb->getOne("SELECT COUNT(*) FROM `" . BIT_DB_PREFIX . - "search_stats` WHERE `term`=?", [ $word ]); + "search_stats` WHERE `term`=?", [ $word ], ); $query = $cant ? "UPDATE `" . BIT_DB_PREFIX . "search_stats` SET `hits`= `hits` + 1 WHERE `term`=?" : "INSERT INTO `" . BIT_DB_PREFIX . "search_stats` (`term`,`hits`) VALUES (?,1)"; @@ -70,7 +71,7 @@ class SearchLib extends BitBase { $bindvars = [ $syllable ]; $age = time() - $this->mDb->getOne( "select `last_updated` from `" . BIT_DB_PREFIX . "search_syllable` where `syllable`=?", - $bindvars); + $bindvars, ); if(!$age || $age > ($search_syll_age * 3600)) {// older than search_syll_age hours $a = $this->refresh_lru_wordlist($syllable); } @@ -81,7 +82,7 @@ class SearchLib extends BitBase { // update lru last used value (Used to purge oldest last used records) $now = time(); $this->mDb->query("update `" . BIT_DB_PREFIX . "search_syllable` set `last_used`=? where `syllable`=?", - [ (int) $now, $syllable ]); + [ (int) $now, $syllable ], ); } return $ret; } @@ -89,14 +90,14 @@ class SearchLib extends BitBase { public function get_lru_wordlist($syllable) { $ret = []; if(!isset($this->wordlist_cache[$syllable])) { - $query = "select `searchword` from `" . BIT_DB_PREFIX . "search_words` where `syllable`=?"; - $result = $this->mDb->query($query, [ $syllable ]); - if ($result->RecordCount() > 0) { - while ($res = $result->fetchRow()) { - $this->wordlist_cache[$syllable][]=$res["searchword"]; - } - $ret = $this->wordlist_cache[$syllable]; - } + $query = "select `searchword` from `" . BIT_DB_PREFIX . "search_words` where `syllable`=?"; + $result = $this->mDb->query($query, [ $syllable ]); + if ($result->RecordCount() > 0) { + while ($res = $result->fetchRow()) { + $this->wordlist_cache[$syllable][]=$res["searchword"]; + } + $ret = $this->wordlist_cache[$syllable]; + } } return $ret; } @@ -124,13 +125,13 @@ class SearchLib extends BitBase { foreach($ret as $searchword) { $this->mDb->query("INSERT INTO `" . BIT_DB_PREFIX . "search_words` (`syllable`,`searchword`) VALUES (?,?)", - [ $syllable, $searchword ], -1, -1); + [ $syllable, $searchword ], -1, -1, ); } // set lru list parameters $now = time(); $this->mDb->query("INSERT INTO `" . BIT_DB_PREFIX . "search_syllable`(`syllable`,`last_used`,`last_updated`) values (?,?,?)", - [ $syllable, (int) $now, (int) $now ]); + [ $syllable, (int) $now, (int) $now ], ); // at random rate: check length of lru list and purge these that // have not been used for long time. This is what a lru list @@ -139,7 +140,7 @@ class SearchLib extends BitBase { srand (ceil($sec + 100 * $usec)); if(rand(1, $search_lru_purge_rate) == 1) { $lrulength = $this->mDb->getOne("SELECT COUNT(*) FROM `" . BIT_DB_PREFIX . - "search_syllable`", []); + "search_syllable`", [], ); if ($lrulength > $search_lru_length) { // only purge if lru list is too long. //purge oldest $oldwords = []; @@ -151,9 +152,9 @@ class SearchLib extends BitBase { } foreach($oldwords as $oldword) { $this->mDb->query("delete from `" . BIT_DB_PREFIX . - "search_words` where `syllable`=?", [ $oldword ], -1, -1); + "search_words` where `syllable`=?", [ $oldword ], -1, -1, ); $this->mDb->query("delete from `" . BIT_DB_PREFIX . - "search_syllable` where `syllable`=?", [ $oldword ], -1, -1); + "search_syllable` where `syllable`=?", [ $oldword ], -1, -1, ); } } @@ -297,7 +298,7 @@ class SearchLib extends BitBase { $pParamHash['cant'] = 0; $ret = []; } - return $ret; + return $ret; } public function mergeResults(&$ret, $result) { diff --git a/includes/classes/SearchStatsLib.php b/includes/classes/SearchStatsLib.php index f38f030..14a207a 100755 --- a/includes/classes/SearchStatsLib.php +++ b/includes/classes/SearchStatsLib.php @@ -14,6 +14,7 @@ */ namespace Bitweaver\Search; + use Bitweaver\BitBase; /** diff --git a/includes/refresh_functions.php b/includes/refresh_functions.php index 3f62674..5cfa144 100755 --- a/includes/refresh_functions.php +++ b/includes/refresh_functions.php @@ -22,7 +22,6 @@ * and pass it to refresh_index() to do the work. */ namespace Bitweaver\Liberty; -use Bitweaver\Liberty\rebuild_index; function random_refresh_index($pContentType = "") { global $gBitSystem; @@ -90,7 +89,7 @@ function refresh_index( $pContentObject = null ) { function refresh_index_oldest(){ global $gBitSystem; $contentId = $gBitSystem->mDb->getOne("SELECT `content_id` FROM `" . BIT_DB_PREFIX . - "search_index` ORDER BY `last_update`", []); + "search_index` ORDER BY `last_update`", [], ); if ( isset($contentId) ) { refresh_index($contentId); } |
