Skip to content
Snippets Groups Projects
Commit f351dfa5 authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FIX #17934 TIME 0:20 fix search town with multiple words

parent 9fa8989b
No related branches found
No related tags found
No related merge requests found
......@@ -1010,18 +1010,28 @@ class AutoCompleteController
}
$searchTown = null;
$searchTowns = [];
if (!empty($queryParams['town'])) {
$searchTown = strtoupper(TextFormatModel::normalize(['string' => $queryParams['town']]));
$searchTowns = strtoupper(TextFormatModel::normalize(['string' => $queryParams['town']]));
$searchTowns = explode(' ', $searchTowns);
}
$searchPostcode = null;
if (!empty($queryParams['postcode'])) {
$searchPostcode = strtoupper(TextFormatModel::normalize(['string' => $queryParams['postcode']]));
}
$postcodes = array_values(array_filter($postcodes, function ($code) use ($searchPostcode, $searchTown) {
return (!empty($searchTown) && strpos($code['town'], $searchTown) !== false) || (!empty($searchPostcode) && strpos($code['postcode'], $searchPostcode) === 0);
$postcodes = array_values(array_filter($postcodes, function ($code) use ($searchPostcode, $searchTowns) {
$townFound = true;
foreach ($searchTowns as $searchTown) {
if (strpos($code['town'], $searchTown) === false) {
$townFound = false;
break;
}
}
return $townFound || (!empty($searchPostcode) && strpos($code['postcode'], $searchPostcode) === 0);
}));
$postcodes = array_slice($postcodes, 0, AutoCompleteController::LIMIT);
return $response->withJson(['postcodes' => $postcodes]);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment