]> git.openstreetmap.org Git - nominatim.git/blobdiff - lib/Result.php
also adapt uses of ClassTypes in website/
[nominatim.git] / lib / Result.php
index 30c5985444b9cf7c0239e57e1d8557bf3b63a4f5..a67c2fe474910a20356ac05edafdac68e3168c17 100644 (file)
@@ -27,6 +27,17 @@ class Result
     /// Subranking within the results (the higher the worse).
     public $iResultRank = 0;
 
+    public function debugInfo()
+    {
+        return array(
+                'Table' => $this->iTable,
+                'ID' => $this->iId,
+                'House number' => $this->iHouseNumber,
+                'Exact Matches' => $this->iExactMatches,
+                'Result rank' => $this->iResultRank
+               );
+    }
+
 
     public function __construct($sId, $iTable = Result::TABLE_PLACEX)
     {
@@ -57,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);
+    }
 }