diff --git a/Sources/Db/APIs/MySQL.php b/Sources/Db/APIs/MySQL.php index a8c0854d1a..3a1be9f16d 100644 --- a/Sources/Db/APIs/MySQL.php +++ b/Sources/Db/APIs/MySQL.php @@ -88,6 +88,11 @@ class MySQL extends DatabaseApi implements DatabaseApiInterface */ public bool $regex_tcl = true; + /** + * + */ + public bool $regex_posix = true; + /********************* * Internal properties *********************/ @@ -2620,12 +2625,8 @@ protected function initialize(array $options = []): void if ($this->get_vendor() === 'MariaDB') { $this->regex_pcre = version_compare(preg_replace('/^(\d+(?:\.\d+)+).*/', '$1', $this->get_version()), '10.0.5', '>='); - - $this->regex_tcl = !$this->regex_pcre; } else { $this->regex_icu = version_compare(preg_replace('/^(\d+(?:\.\d+)+).*/', '$1', $this->get_version()), '8.0.4', '>='); - - $this->regex_tcl = !$this->regex_icu; } $this->character_set = strtolower($this->detect_charset('messages', 'body')); diff --git a/Sources/Db/APIs/PostgreSQL.php b/Sources/Db/APIs/PostgreSQL.php index 472242e4f6..54170f4f51 100644 --- a/Sources/Db/APIs/PostgreSQL.php +++ b/Sources/Db/APIs/PostgreSQL.php @@ -75,6 +75,11 @@ class PostgreSQL extends DatabaseApi implements DatabaseApiInterface */ public bool $regex_tcl = true; + /** + * + */ + public bool $regex_posix = true; + /********************* * Internal properties *********************/ diff --git a/Sources/Db/DatabaseApi.php b/Sources/Db/DatabaseApi.php index a2e0efddb0..d51f8e1edd 100644 --- a/Sources/Db/DatabaseApi.php +++ b/Sources/Db/DatabaseApi.php @@ -111,6 +111,13 @@ abstract class DatabaseApi */ public bool $regex_tcl; + /** + * @var bool + * + * Whether the database supports POSIX regular expressions. + */ + public bool $regex_posix; + /** * @var string * diff --git a/Sources/Search/SearchApi.php b/Sources/Search/SearchApi.php index 53559dd214..5b9d3a9a37 100644 --- a/Sources/Search/SearchApi.php +++ b/Sources/Search/SearchApi.php @@ -1306,6 +1306,11 @@ protected function wordBoundaryWrapper(string $str): string return \sprintf('\\y%s\\y', $str); } + // POSIX uses `[[:<:]]` and `[[:>:]]` as the word boundaries. + if (Db::$db->regex_posix) { + return \sprintf('[[:<:]]%s[[:>:]]', $str); + } + // We should never get here, but just in case... return $str; }