Skip to content

Commit bf2d74f

Browse files
committed
Fixed some aliases being caught as acronyms
1 parent d5cd155 commit bf2d74f

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

src/AppBundle/Controller/SearchController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,14 +425,15 @@ public function displayAction(
425425
$rows = $cardsData->get_search_rows($conditions, $sort, $locale);
426426

427427
// If there are no results, and no specific criteria were searched, try again but force acronyms
428-
if (!$rows && !array_filter($conditions, function($c) {return $c[0] != "_";})) {
429-
$capsConditions = array_map(function($c) {return ["_", $c[1], strtoupper($c[2])];}, $conditions);
428+
if (!$rows && $cardsData->simplifyConditions($conditions)) {
429+
$capsConditions = [["_", ":", strtoupper($conditions[0][2])]];
430430
$rows = $cardsData->get_search_rows($capsConditions, $sort, $locale);
431431

432-
// If there are still no results, try again but with aliases
432+
// If there are results, rebuild the query from the uppercase conditions
433433
if ($rows) {
434434
$conditions = $capsConditions;
435435
}
436+
// If there are still no results, try again but with aliases
436437
else {
437438
$cardsData->unaliasCardNames($conditions);
438439
$rows = $cardsData->get_search_rows($conditions, $sort, $locale);

src/AppBundle/Service/CardsData.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -947,14 +947,31 @@ public function validateConditions(array &$conditions)
947947
}
948948
}
949949

950+
public function simplifyConditions(array &$conditions)
951+
{
952+
// Checks if the given conditions are valid
953+
if (array_filter($conditions, function($c) {return $c[0] != "_" || $c[1] != ":";}))
954+
return false;
955+
956+
// Combine all conditions into a single string
957+
$s = preg_replace("/[^A-Za-z0-9 ]/", "", implode(" ", array_map(function($c) {return $c[2];}, $conditions)));
958+
959+
// Update the array if the combined conditions are non-empty
960+
if (!$s)
961+
return false;
962+
$conditions = [["_", ":", strtolower($s)]];
963+
return true;
964+
}
965+
966+
// Assumes given conditions are simplified
950967
public function unaliasCardNames(array &$conditions)
951968
{
952-
// Join all the conditions without criteria into a single string
953-
$title = preg_replace("/[^A-Za-z0-9 ]/", "", implode(" ", array_map(function($c) {return $c[0] == "_" ? strtolower($c[2]) : "";}, $conditions)));
969+
// Get the simplified conditions
970+
$title = $conditions[0][2];
954971

955-
if (!$title) {
972+
// Check the conditions are non-empty
973+
if (!$title)
956974
return;
957-
}
958975

959976
// If they are the substring of an alias for a card, replace the conditions with that card's name
960977
if ($match = current(preg_grep("/^$title/", array_keys($this->cardAliases)))) {

web/card_aliases.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ yogurt : Economic Warfare
9898
cell phones : 02069
9999
cell phone man : 02069
100100
mister phones : 02069
101-
# mr phones : 02069
101+
mr phones : 02069
102102

103103
# Cars
104104
nice car : Sports Hopper

0 commit comments

Comments
 (0)