diff --git a/includes/components/filter.class.php b/includes/components/filter.class.php index 13b44d32..de0339f2 100644 --- a/includes/components/filter.class.php +++ b/includes/components/filter.class.php @@ -635,7 +635,7 @@ abstract class Filter // note: a fulltext search purely from exclude tokens will return no result foreach ($fulltext as $ft) - $this->ftTokens[$field][] = ($ex ? '-' : '+') . $ft . '*'; + $this->ftTokens[$field][] = ($ex ? '-' : '+') . '(' . $ft . '* ' . Util::strrev($ft) . '*)'; } } diff --git a/includes/components/search.class.php b/includes/components/search.class.php index 78f52f21..5587071c 100644 --- a/includes/components/search.class.php +++ b/includes/components/search.class.php @@ -118,7 +118,7 @@ class Search // note: a fulltext search purely from exclude tokens will return no result foreach ($fulltext as $ft) - $this->fulltext[] = ($ex ? '-' : '+') . $ft . '*'; + $this->fulltext[] = ($ex ? '-' : '+') . '(' . $ft . '* ' . Util::strrev($ft) . '*)'; } else $this->invalid[] = $raw; diff --git a/includes/utilities.php b/includes/utilities.php index daf48799..39e9f297 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -360,6 +360,15 @@ abstract class Util return mb_strtolower($str); } + public static function strrev(string $str) : string + { + $out = ''; + for ($i = 1, $len = mb_strlen($str); $i <= $len; $i++) + $out .= mb_substr($str, -$i, 1); + + return $out; + } + // doesn't handle scientific notation .. why would you input 3e3 for 3000..? public static function checkNumeric(mixed &$data, int $typeCast = NUM_ANY) : bool { diff --git a/setup/sql/updates/1774728772_01.sql b/setup/sql/updates/1774728772_01.sql new file mode 100644 index 00000000..f30e8121 --- /dev/null +++ b/setup/sql/updates/1774728772_01.sql @@ -0,0 +1 @@ +UPDATE `aowow_dbversion` SET `sql` = CONCAT(IFNULL(`sql`, ''), ' search'); diff --git a/setup/tools/sqlgen/search.ss.php b/setup/tools/sqlgen/search.ss.php index 09f6f765..6c60bee4 100644 --- a/setup/tools/sqlgen/search.ss.php +++ b/setup/tools/sqlgen/search.ss.php @@ -289,9 +289,9 @@ CLISetup::registerSetup("sql", new class extends SetupScript $buff = self::normalize(str_replace('
', ' ', $_)); } - if ($_ = $desc ?: Util::localizedString($spell, 'description', true)) + if (!$desc && ($_ = Util::localizedString($spell, 'description', true))) $desc = self::normalize($_); - if ($_ = $buff ?: Util::localizedString($spell, 'buff', true)) + if (!$buff && ($_ = Util::localizedString($spell, 'buff', true))) $buff = self::normalize($_); if ($_ = Util::localizedString($spell, 'name', true)) $name = self::normalize($_); @@ -321,7 +321,7 @@ CLISetup::registerSetup("sql", new class extends SetupScript $row[$key] = self::normalize($row[$key] ?? ''); } - // e.g. "Zul'Aman O'Reilly" => "Zul Aman ZulAman OReilly Reilly" + // e.g. "Zul'Aman O'Reilly" => "Zul Aman ZulAman OReilly Reilly luZ namA luZnamA yllieRO yllieR" private static function normalize(?string $words) : ?string { if (!$words) @@ -351,7 +351,13 @@ CLISetup::registerSetup("sql", new class extends SetupScript $result[] = $word; } - return $result ? implode(' ', array_unique($result)) : null; + if (!$result) + return null; + + $result = array_unique($result); + $reversed = array_map(Util::strrev(...), $result); + + return implode(' ', array_merge($result, $reversed)); } });