From bfe51197429c9436034bb4d25931ad4d687d09c8 Mon Sep 17 00:00:00 2001 From: Brian Quinion Date: Sun, 1 Apr 2012 02:38:40 +0100 Subject: [PATCH 1/1] Update details.php to show linked places --- lib/template/details-html.php | 26 +++++++++++++++++++++++++- sql/functions.sql | 6 ++---- website/details.php | 9 ++++++++- website/search.php | 1 + 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/lib/template/details-html.php b/lib/template/details-html.php index aa27664b..c438659b 100644 --- a/lib/template/details-html.php +++ b/lib/template/details-html.php @@ -142,7 +142,7 @@ if (isset($aPolyPoints)) if ($sOSMType) echo ', '.$sOSMType.' '.$aAddressLine['osm_id'].''; echo ', '.$aAddressLine['admin_level'].''; echo ', '.$aAddressLine['rank_search_label'].''; - echo ', '.($aAddressLine['fromarea']=='t'?'Polygon':'Point').''; +// echo ', '.($aAddressLine['fromarea']=='t'?'Polygon':'Point').''; echo ', '.$aAddressLine['distance'].''; echo ' GOTO'; echo ')'; @@ -150,6 +150,30 @@ if (isset($aPolyPoints)) } echo ''; + if ($aLinkedLines) + { + echo '

Linked Places

'; + echo '
'; + foreach($aLinkedLines as $aAddressLine) + { + $sOSMType = ($aAddressLine['osm_type'] == 'N'?'node':($aAddressLine['osm_type'] == 'W'?'way':($aAddressLine['osm_type'] == 'R'?'relation':''))); + + echo '
'; + echo ''.(trim($aAddressLine['localname'])?$aAddressLine['localname']:'No Name').''; + echo ' ('; + echo 'Type: '.$aAddressLine['class'].':'.$aAddressLine['type'].''; + if ($sOSMType) echo ', '.$sOSMType.' '.$aAddressLine['osm_id'].''; + echo ', '.$aAddressLine['admin_level'].''; + echo ', '.$aAddressLine['rank_search_label'].''; +// echo ', '.($aAddressLine['fromarea']=='t'?'Polygon':'Point').''; + echo ', '.$aAddressLine['distance'].''; + echo ' GOTO'; + echo ')'; + echo '
'; + } + echo '
'; + } + if ($aPlaceSearchNameKeywords) { echo '

Name Keywords

'; diff --git a/sql/functions.sql b/sql/functions.sql index 0174387b..c825712d 100644 --- a/sql/functions.sql +++ b/sql/functions.sql @@ -1481,7 +1481,6 @@ BEGIN -- mark the linked place (excludes from search results) UPDATE placex set linked_place_id = NEW.place_id where place_id = linkedPlacex.place_id; - DELETE from search_name where place_id = linkedPlacex.place_id; END LOOP; @@ -1505,7 +1504,6 @@ BEGIN -- mark the linked place (excludes from search results) UPDATE placex set linked_place_id = NEW.place_id where place_id = linkedPlacex.place_id; - DELETE from search_name where place_id = linkedPlacex.place_id; END IF; END LOOP; @@ -1534,12 +1532,12 @@ BEGIN -- mark the linked place (excludes from search results) UPDATE placex set linked_place_id = NEW.place_id where place_id = linkedPlacex.place_id; - DELETE from search_name where place_id = linkedPlacex.place_id; + END LOOP; END IF; IF NEW.centroid IS NOT NULL THEN - place_centroid := NEW.centroid + place_centroid := NEW.centroid; END IF; END IF; diff --git a/website/details.php b/website/details.php index a4cb8b96..7c6ad8ad 100755 --- a/website/details.php +++ b/website/details.php @@ -109,12 +109,19 @@ // Address $aAddressLines = getAddressDetails($oDB, $sLanguagePrefArraySQL, $iPlaceID, $aPointDetails['country_code'], true); + // Linked places + $sSQL = "select placex.place_id, osm_type, osm_id, class, type, housenumber, admin_level, rank_address, ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') as isarea, st_distance(geometry, placegeometry) as distance, "; + $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) as localname, length(name::text) as namelength "; + $sSQL .= " from placex, (select geometry as placegeometry from placex where place_id = $iPlaceID) as x"; + $sSQL .= " where linked_place_id = $iPlaceID"; + $sSQL .= " order by rank_address asc,rank_search asc,get_name_by_language(name,$sLanguagePrefArraySQL),housenumber"; + $aLinkedLines = $oDB->getAll($sSQL); + // All places this is an imediate parent of $sSQL = "select placex.place_id, osm_type, osm_id, class, type, housenumber, admin_level, rank_address, ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') as isarea, st_distance(geometry, placegeometry) as distance, "; $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) as localname, length(name::text) as namelength "; $sSQL .= " from placex, (select geometry as placegeometry from placex where place_id = $iPlaceID) as x"; $sSQL .= " where parent_place_id = $iPlaceID"; -// $sSQL .= " and type != 'postcode'"; $sSQL .= " order by rank_address asc,rank_search asc,get_name_by_language(name,$sLanguagePrefArraySQL),housenumber"; $aParentOfLines = $oDB->getAll($sSQL); diff --git a/website/search.php b/website/search.php index c00c4cfd..88248cea 100755 --- a/website/search.php +++ b/website/search.php @@ -1012,6 +1012,7 @@ $sSQL .= "coalesce(importance,0.9-(rank_search::float/30)) as importance "; $sSQL .= "from placex where place_id in ($sPlaceIDs) "; $sSQL .= "and placex.rank_address between $iMinAddressRank and $iMaxAddressRank "; + $sSQL .= "and linked_place_id is null "; $sSQL .= "group by osm_type,osm_id,class,type,admin_level,rank_search,rank_address,country_code,importance"; if (!$bDeDupe) $sSQL .= ",place_id"; $sSQL .= ",get_address_by_language(place_id, $sLanguagePrefArraySQL) "; -- 2.39.5