From fd08d419629c51cb2c7b1e90814d596819d20640 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sun, 8 Oct 2017 16:03:30 +0200 Subject: [PATCH] move Search dump function into SearchDescription class --- lib/SearchDescription.php | 50 ++++++++++++++++++++++++++++++++++ lib/lib.php | 57 +++------------------------------------ 2 files changed, 53 insertions(+), 54 deletions(-) diff --git a/lib/SearchDescription.php b/lib/SearchDescription.php index d18e7eab..a8285299 100644 --- a/lib/SearchDescription.php +++ b/lib/SearchDescription.php @@ -19,6 +19,27 @@ abstract class Operator 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; } + //////////// Debugging functions + + function dumpAsHtmlTableRow(&$aWordIDs) + { + $kf = function($k) use (&$aWordIDs) { return $aWordIDs[$k]; }; + + echo ""; + echo "$this->iSearchRank"; + echo "".join(', ', array_map($kf, $this->aName)).""; + echo "".join(', ', array_map($kf, $this->aNameNonSearch)).""; + echo "".join(', ', array_map($kf, $this->aAddress)).""; + echo "".join(', ', array_map($kf, $this->aAddressNonSearch)).""; + echo "".$this->sCountryCode.""; + echo "".Operator::toString($this->iOperator).""; + echo "".$this->sClass.""; + echo "".$this->sType.""; + echo "".$this->sPostcode.""; + echo "".$this->sHouseNumber.""; + + if ($this->oNearPoint) { + echo "".$this->oNearPoint->lat().""; + echo "".$this->oNearPoint->lon().""; + echo "".$this->oNearPoint->radius().""; + } else { + echo ""; + } + + echo ""; + } }; diff --git a/lib/lib.php b/lib/lib.php index f92985ba..969d58a3 100644 --- a/lib/lib.php +++ b/lib/lib.php @@ -481,7 +481,8 @@ function _debugDumpGroupedSearches($aData, $aTokens) 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 "LatLonRadius"; foreach ($aData as $iRank => $aRankedSet) { foreach ($aRankedSet as $aRow) { - echo ""; - echo "$iRank"; - - echo ""; - $sSep = ''; - foreach ($aRow['aName'] as $iWordID) { - echo $sSep.'#'.$aWordsIDs[$iWordID].'#'; - $sSep = ', '; - } - echo ""; - - echo ""; - $sSep = ''; - foreach ($aRow['aNameNonSearch'] as $iWordID) { - echo $sSep.'#'.$aWordsIDs[$iWordID].'#'; - $sSep = ', '; - } - echo ""; - - echo ""; - $sSep = ''; - foreach ($aRow['aAddress'] as $iWordID) { - echo $sSep.'#'.$aWordsIDs[$iWordID].'#'; - $sSep = ', '; - } - echo ""; - - echo ""; - $sSep = ''; - foreach ($aRow['aAddressNonSearch'] as $iWordID) { - echo $sSep.'#'.$aWordsIDs[$iWordID].'#'; - $sSep = ', '; - } - echo ""; - - echo "".$aRow['sCountryCode'].""; - - echo "".$aRow['sOperator'].""; - echo "".$aRow['sClass'].""; - echo "".$aRow['sType'].""; - - echo "".$aRow['sPostcode'].""; - echo "".$aRow['sHouseNumber'].""; - - if ($aRow['oNear']) { - echo "".$aRow['oNear']->lat().""; - echo "".$aRow['oNear']->lon().""; - echo "".$aRow['oNear']->radius().""; - } else { - echo ""; - } - - echo ""; + $aRow->dumpAsHtmlTableRow($aWordsIDs); } } echo ""; -- 2.39.5