Search/Indexing
* add reversed words and update token processing to allow fulltext search to match end of word (e.g. searching 'wind -storm' will now find 'whisperwind' or 'windrunner' and ignore 'stormwind') * fix search token duplication for spells
This commit is contained in:
parent
764ea1c7fa
commit
681d29e5f3
5 changed files with 22 additions and 6 deletions
|
|
@ -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) . '*)';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
1
setup/sql/updates/1774728772_01.sql
Normal file
1
setup/sql/updates/1774728772_01.sql
Normal file
|
|
@ -0,0 +1 @@
|
|||
UPDATE `aowow_dbversion` SET `sql` = CONCAT(IFNULL(`sql`, ''), ' search');
|
||||
|
|
@ -289,9 +289,9 @@ CLISetup::registerSetup("sql", new class extends SetupScript
|
|||
$buff = self::normalize(str_replace('<br />', ' ', $_));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue