X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/64fa70ac0aaaad3e2fa881cde7c7f2050e151141..765a932561d7c9b3dd6954b41b2e34e476fe2a26:/lib/Result.php diff --git a/lib/Result.php b/lib/Result.php index d69ac62f..a67c2fe4 100644 --- a/lib/Result.php +++ b/lib/Result.php @@ -68,4 +68,32 @@ class Result return $sHousenumbers; } + + /** + * Split a result array into highest ranked result and the rest + * + * @param object[] $aResults List of results to split. + * + * @return array[] + */ + public static function splitResults($aResults) + { + $aHead = array(); + $aTail = array(); + $iMinRank = 10000; + + foreach ($aResults as $oRes) { + if ($oRes->iResultRank < $iMinRank) { + $aTail = array_merge($aTail, $aHead); + $aHead = array($oRes->iId => $oRes); + $iMinRank = $oRes->iResultRank; + } elseif ($oRes->iResultRank == $iMinRank) { + $aHead[$oRes->iId] = $oRes; + } else { + $aTail[$oRes->iId] = $oRes; + } + } + + return array('head' => $aHead, 'tail' => $aTail); + } }