mirror of
https://github.com/osm-search/Nominatim.git
synced 2024-11-23 21:54:10 +03:00
Merge pull request #1295 from mtmail/move-searchrank-labels-to-php
Remove get_addressrank_label. Move get_searchrank_label to PHP
This commit is contained in:
commit
bdd64093e5
22
lib/lib.php
22
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;
|
||||
}
|
||||
|
@ -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 $$
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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 ';
|
||||
|
Loading…
Reference in New Issue
Block a user