]> git.openstreetmap.org Git - nominatim.git/commitdiff
move Search dump function into SearchDescription class
authorSarah Hoffmann <lonvia@denofr.de>
Sun, 8 Oct 2017 14:03:30 +0000 (16:03 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Sun, 8 Oct 2017 14:05:27 +0000 (16:05 +0200)
lib/SearchDescription.php
lib/lib.php

index d18e7eab35790b3208a6c1cde94508875afbc011..a82852990e6f589f3bc57d9f2bd6c3f630c90ae9 100644 (file)
@@ -19,6 +19,27 @@ abstract class Operator
     const NAME = 4;
     /// Search for postcodes.
     const POSTCODE = 5;
     const NAME = 4;
     /// Search for postcodes.
     const POSTCODE = 5;
+
+    private $aConstantNames = null;
+
+    public static function toString($iOperator)
+    {
+        if ($iOperator == Operator::NONE) {
+            return '';
+        }
+
+        if ($aConstantNames === null) {
+            $oReflector = new \ReflectionClass ('Nominatim\Operator');
+            $aConstants = $oReflector->getConstants();
+
+            $aConstantNames = array();
+            foreach ($aConstants as $sName => $iValue) {
+                $aConstantNames[$iValue] = $sName;
+            }
+        }
+
+        return $aConstantNames[$iOperator];
+    }
 }
 
 /**
 }
 
 /**
@@ -884,4 +905,33 @@ class SearchDescription
         return $a->iSearchRank < $b->iSearchRank ? -1 : 1;
     }
 
         return $a->iSearchRank < $b->iSearchRank ? -1 : 1;
     }
 
+    //////////// Debugging functions
+
+    function dumpAsHtmlTableRow(&$aWordIDs)
+    {
+        $kf = function($k) use (&$aWordIDs) { return $aWordIDs[$k]; };
+
+        echo "<tr>";
+        echo "<td>$this->iSearchRank</td>";
+        echo "<td>".join(', ', array_map($kf, $this->aName))."</td>";
+        echo "<td>".join(', ', array_map($kf, $this->aNameNonSearch))."</td>";
+        echo "<td>".join(', ', array_map($kf, $this->aAddress))."</td>";
+        echo "<td>".join(', ', array_map($kf, $this->aAddressNonSearch))."</td>";
+        echo "<td>".$this->sCountryCode."</td>";
+        echo "<td>".Operator::toString($this->iOperator)."</td>";
+        echo "<td>".$this->sClass."</td>";
+        echo "<td>".$this->sType."</td>";
+        echo "<td>".$this->sPostcode."</td>";
+        echo "<td>".$this->sHouseNumber."</td>";
+
+        if ($this->oNearPoint) {
+            echo "<td>".$this->oNearPoint->lat()."</td>";
+            echo "<td>".$this->oNearPoint->lon()."</td>";
+            echo "<td>".$this->oNearPoint->radius()."</td>";
+        } else {
+            echo "<td></td><td></td><td></td>";
+        }
+
+        echo "</tr>";
+    }
 };
 };
index f92985bac694c2f02fbdc54ffcde63c6eb4a39f3..969d58a33cc353d8f9f3fe7506b81e0cbc6afa73 100644 (file)
@@ -481,7 +481,8 @@ function _debugDumpGroupedSearches($aData, $aTokens)
         foreach ($aTokens as $sToken => $aWords) {
             if ($aWords) {
                 foreach ($aWords as $aToken) {
         foreach ($aTokens as $sToken => $aWords) {
             if ($aWords) {
                 foreach ($aWords as $aToken) {
-                    $aWordsIDs[$aToken['word_id']] = $sToken.'('.$aToken['word_id'].')';
+                    $aWordsIDs[$aToken['word_id']] =
+                        '#'.$sToken.'('.$aToken['word_id'].')#';
                 }
             }
         }
                 }
             }
         }
@@ -493,59 +494,7 @@ function _debugDumpGroupedSearches($aData, $aTokens)
     echo "<th>Lat</th><th>Lon</th><th>Radius</th></tr>";
     foreach ($aData as $iRank => $aRankedSet) {
         foreach ($aRankedSet as $aRow) {
     echo "<th>Lat</th><th>Lon</th><th>Radius</th></tr>";
     foreach ($aData as $iRank => $aRankedSet) {
         foreach ($aRankedSet as $aRow) {
-            echo "<tr>";
-            echo "<td>$iRank</td>";
-
-            echo "<td>";
-            $sSep = '';
-            foreach ($aRow['aName'] as $iWordID) {
-                echo $sSep.'#'.$aWordsIDs[$iWordID].'#';
-                $sSep = ', ';
-            }
-            echo "</td>";
-
-            echo "<td>";
-            $sSep = '';
-            foreach ($aRow['aNameNonSearch'] as $iWordID) {
-                echo $sSep.'#'.$aWordsIDs[$iWordID].'#';
-                $sSep = ', ';
-            }
-            echo "</td>";
-
-            echo "<td>";
-            $sSep = '';
-            foreach ($aRow['aAddress'] as $iWordID) {
-                echo $sSep.'#'.$aWordsIDs[$iWordID].'#';
-                $sSep = ', ';
-            }
-            echo "</td>";
-
-            echo "<td>";
-            $sSep = '';
-            foreach ($aRow['aAddressNonSearch'] as $iWordID) {
-                echo $sSep.'#'.$aWordsIDs[$iWordID].'#';
-                $sSep = ', ';
-            }
-            echo "</td>";
-
-            echo "<td>".$aRow['sCountryCode']."</td>";
-
-            echo "<td>".$aRow['sOperator']."</td>";
-            echo "<td>".$aRow['sClass']."</td>";
-            echo "<td>".$aRow['sType']."</td>";
-
-            echo "<td>".$aRow['sPostcode']."</td>";
-            echo "<td>".$aRow['sHouseNumber']."</td>";
-
-            if ($aRow['oNear']) {
-                echo "<td>".$aRow['oNear']->lat()."</td>";
-                echo "<td>".$aRow['oNear']->lon()."</td>";
-                echo "<td>".$aRow['oNear']->radius()."</td>";
-            } else {
-                echo "<td></td><td></td><td></td>";
-            }
-
-            echo "</tr>";
+            $aRow->dumpAsHtmlTableRow($aWordsIDs);
         }
     }
     echo "</table>";
         }
     }
     echo "</table>";