From 853b5363942bbbcc603c18f63154cca7c2f404a8 Mon Sep 17 00:00:00 2001 From: marc tobias Date: Mon, 28 Jan 2019 19:38:05 +0100 Subject: [PATCH] Remove get_addressrank_label. Move get_searchrank_label to PHP --- lib/lib.php | 22 +++++++++ sql/functions.sql | 90 ---------------------------------- test/php/Nominatim/LibTest.php | 8 +++ website/details.php | 2 +- 4 files changed, 31 insertions(+), 91 deletions(-) diff --git a/lib/lib.php b/lib/lib.php index 39462ae3..d77a82c1 100644 --- a/lib/lib.php +++ b/lib/lib.php @@ -228,3 +228,25 @@ function closestHouseNumber($aRow) return max(min($aRow['endnumber'], $iHn), $aRow['startnumber']); } + +function getSearchRankLabel($iRank) +{ + if (!isset($iRank)) return 'unknown'; + if ($iRank < 2) return 'continent'; + if ($iRank < 4) return 'sea'; + if ($iRank < 8) return 'country'; + if ($iRank < 12) return 'state'; + if ($iRank < 16) return 'county'; + if ($iRank == 16) return 'city'; + if ($iRank == 17) return 'town / island'; + if ($iRank == 18) return 'village / hamlet'; + if ($iRank == 20) return 'suburb'; + if ($iRank == 21) return 'postcode area'; + if ($iRank == 22) return 'croft / farm / locality / islet'; + if ($iRank == 23) return 'postcode area'; + if ($iRank == 25) return 'postcode point'; + if ($iRank == 26) return 'street / major landmark'; + if ($iRank == 27) return 'minory street / path'; + if ($iRank == 28) return 'house / building'; + return 'other: ' . $iRank; +} diff --git a/sql/functions.sql b/sql/functions.sql index 179975d8..73790353 100644 --- a/sql/functions.sql +++ b/sql/functions.sql @@ -2495,96 +2495,6 @@ $$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION get_searchrank_label(rank INTEGER) RETURNS TEXT - AS $$ -DECLARE -BEGIN - IF rank < 2 THEN - RETURN 'Continent'; - ELSEIF rank < 4 THEN - RETURN 'Sea'; - ELSEIF rank < 8 THEN - RETURN 'Country'; - ELSEIF rank < 12 THEN - RETURN 'State'; - ELSEIF rank < 16 THEN - RETURN 'County'; - ELSEIF rank = 16 THEN - RETURN 'City'; - ELSEIF rank = 17 THEN - RETURN 'Town / Island'; - ELSEIF rank = 18 THEN - RETURN 'Village / Hamlet'; - ELSEIF rank = 20 THEN - RETURN 'Suburb'; - ELSEIF rank = 21 THEN - RETURN 'Postcode Area'; - ELSEIF rank = 22 THEN - RETURN 'Croft / Farm / Locality / Islet'; - ELSEIF rank = 23 THEN - RETURN 'Postcode Area'; - ELSEIF rank = 25 THEN - RETURN 'Postcode Point'; - ELSEIF rank = 26 THEN - RETURN 'Street / Major Landmark'; - ELSEIF rank = 27 THEN - RETURN 'Minory Street / Path'; - ELSEIF rank = 28 THEN - RETURN 'House / Building'; - ELSE - RETURN 'Other: '||rank; - END IF; - -END; -$$ -LANGUAGE plpgsql; - -CREATE OR REPLACE FUNCTION get_addressrank_label(rank INTEGER) RETURNS TEXT - AS $$ -DECLARE -BEGIN - IF rank = 0 THEN - RETURN 'None'; - ELSEIF rank < 2 THEN - RETURN 'Continent'; - ELSEIF rank < 4 THEN - RETURN 'Sea'; - ELSEIF rank = 5 THEN - RETURN 'Postcode'; - ELSEIF rank < 8 THEN - RETURN 'Country'; - ELSEIF rank < 12 THEN - RETURN 'State'; - ELSEIF rank < 16 THEN - RETURN 'County'; - ELSEIF rank = 16 THEN - RETURN 'City'; - ELSEIF rank = 17 THEN - RETURN 'Town / Village / Hamlet'; - ELSEIF rank = 20 THEN - RETURN 'Suburb'; - ELSEIF rank = 21 THEN - RETURN 'Postcode Area'; - ELSEIF rank = 22 THEN - RETURN 'Croft / Farm / Locality / Islet'; - ELSEIF rank = 23 THEN - RETURN 'Postcode Area'; - ELSEIF rank = 25 THEN - RETURN 'Postcode Point'; - ELSEIF rank = 26 THEN - RETURN 'Street / Major Landmark'; - ELSEIF rank = 27 THEN - RETURN 'Minory Street / Path'; - ELSEIF rank = 28 THEN - RETURN 'House / Building'; - ELSE - RETURN 'Other: '||rank; - END IF; - -END; -$$ -LANGUAGE plpgsql; - CREATE OR REPLACE FUNCTION aux_create_property(pointgeo GEOMETRY, in_housenumber TEXT, in_street TEXT, in_isin TEXT, in_postcode TEXT, in_countrycode char(2)) RETURNS INTEGER AS $$ diff --git a/test/php/Nominatim/LibTest.php b/test/php/Nominatim/LibTest.php index dbf8feca..a80ef73b 100644 --- a/test/php/Nominatim/LibTest.php +++ b/test/php/Nominatim/LibTest.php @@ -173,4 +173,12 @@ class LibTest extends \PHPUnit\Framework\TestCase // start == end $this->closestHouseNumberEvenOddOther(50, 50, 0.5, array('even' => 50, 'odd' => 50, 'other' => 50)); } + + public function testGetSearchRankLabel() + { + $this->assertEquals('unknown', getSearchRankLabel(null)); + $this->assertEquals('continent', getSearchRankLabel(0)); + $this->assertEquals('continent', getSearchRankLabel(1)); + $this->assertEquals('other: 30', getSearchRankLabel(30)); + } } diff --git a/website/details.php b/website/details.php index 474c1d87..4a67f70a 100644 --- a/website/details.php +++ b/website/details.php @@ -106,7 +106,6 @@ $sSQL .= ' ROUND(EXTRACT(epoch FROM indexed_date)) AS indexed_epoch,'; $sSQL .= ' parent_place_id, '; $sSQL .= ' rank_address, '; $sSQL .= ' rank_search, '; -$sSQL .= ' get_searchrank_label(rank_search) AS rank_search_label,'; // only used in HTML output $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) AS localname, "; $sSQL .= " ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') AS isarea, "; $sSQL .= ' ST_y(centroid) AS lat, '; @@ -136,6 +135,7 @@ if (!$aPointDetails) { $aPointDetails['localname'] = $aPointDetails['localname']?$aPointDetails['localname']:$aPointDetails['housenumber']; $aPointDetails['icon'] = Nominatim\ClassTypes\getProperty($aPointDetails, 'icon', false); +$aPointDetails['rank_search_label'] = getSearchRankLabel($aPointDetails['rank_search']); // only used in HTML format // Get all alternative names (languages, etc) $sSQL = 'SELECT (each(name)).key,(each(name)).value FROM placex ';