Add MysqlSearchEngine::getMinTokenSize() as a replacement for getFulltextMinimumWordL...
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 15 Mar 2022 14:39:53 +0000 (15:39 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 15 Mar 2022 14:39:53 +0000 (15:39 +0100)
This new method is private, because it is considered an implementation detail.

wcfsetup/install/files/lib/system/search/mysql/MysqlSearchEngine.class.php

index 5e0a93c04b34bfa48f058ca4beefe652cf86197f..000e036943df43ef8db1bcc0190563a7773bbc7d 100644 (file)
@@ -2,7 +2,7 @@
 
 namespace wcf\system\search\mysql;
 
-use wcf\system\database\DatabaseException;
+use wcf\system\database\exception\DatabaseQueryExecutionException;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\SystemException;
 use wcf\system\search\AbstractSearchEngine;
@@ -26,6 +26,11 @@ class MysqlSearchEngine extends AbstractSearchEngine
      */
     protected $ftMinWordLen;
 
+    /**
+     * @var int
+     */
+    private $minTokenSize;
+
     /**
      * @inheritDoc
      */
@@ -492,20 +497,25 @@ class MysqlSearchEngine extends AbstractSearchEngine
     protected function getFulltextMinimumWordLength()
     {
         if ($this->ftMinWordLen === null) {
-            $sql = "SHOW VARIABLES LIKE 'innodb_ft_min_token_size'";
+            $this->ftMinWordLen = $this->getMinTokenSize();
+        }
+
+        return $this->ftMinWordLen;
+    }
 
+    private function getMinTokenSize(): int
+    {
+        if (!isset($this->minTokenSize)) {
             try {
+                $sql = "SELECT @@innodb_ft_min_token_size";
                 $statement = WCF::getDB()->prepareStatement($sql);
                 $statement->execute();
-                $row = $statement->fetchArray();
-            } catch (DatabaseException $e) {
-                // fallback if user is disallowed to issue 'SHOW VARIABLES'
-                $row = ['Value' => 3];
+                $this->minTokenSize = $statement->fetchSingleColumn();
+            } catch (DatabaseQueryExecutionException $e) {
+                $this->minTokenSize = 3;
             }
-
-            $this->ftMinWordLen = $row['Value'];
         }
 
-        return $this->ftMinWordLen;
+        return $this->minTokenSize;
     }
 }