]> git.openstreetmap.org Git - nominatim.git/commitdiff
fix search by just country code. Re-order some search results (admin boundaries...
authorBrian Quinion <openstreetmap@brian.quinion.co.uk>
Tue, 8 Feb 2011 14:21:39 +0000 (14:21 +0000)
committerBrian Quinion <openstreetmap@brian.quinion.co.uk>
Tue, 8 Feb 2011 14:21:39 +0000 (14:21 +0000)
lib/lib.php
website/search.php

index 115a9495aa4cbfb03548b1e9db2c135021e3cfec..8dc2570cd23f06150e8df84db47ce9f85472f3ea 100644 (file)
                        return ($a['aPointPolygon']['numfeatures'] > $b['aPointPolygon']['numfeatures']?-1:1);
                if ($a['aPointPolygon']['area'] != $b['aPointPolygon']['area'])
                        return ($a['aPointPolygon']['area'] > $b['aPointPolygon']['area']?-1:1);
-               if ($a['levenshtein'] != $b['levenshtein'])
-                       return ($a['levenshtein'] < $b['levenshtein']?-1:1);
+//             if ($a['levenshtein'] != $b['levenshtein'])
+//                     return ($a['levenshtein'] < $b['levenshtein']?-1:1);
+               if ($a['rank_search'] != $b['rank_search'])
+                       return ($a['rank_search'] < $b['rank_search']?-1:1);
                if ($a['importance'] != $b['importance'])
                        return ($a['importance'] < $b['importance']?-1:1);
                return ($a['foundorder'] < $b['foundorder']?-1:1);
        {
                return array(
  'boundary:administrative:2' => array('label'=>'Country','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,),
+ 'place:country' => array('label'=>'Country','frequency'=>0,'icon'=>'poi_boundary_administrative','defzoom'=>6, 'defdiameter' => 15,),
  'boundary:administrative:4' => array('label'=>'State','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,),
+ 'place:state' => array('label'=>'State','frequency'=>0,'icon'=>'poi_boundary_administrative','defzoom'=>8, 'defdiameter' => 5.12,),
  'boundary:administrative:5' => array('label'=>'State District','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,),
  'boundary:administrative:6' => array('label'=>'County','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,),
+ 'place:county' => array('label'=>'County','frequency'=>108,'icon'=>'poi_boundary_administrative','defzoom'=>10, 'defdiameter' => 1.28,),
  'boundary:administrative:8' => array('label'=>'City','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,),
+ 'place:city' => array('label'=>'City','frequency'=>66,'icon'=>'poi_place_city','defzoom'=>12, 'defdiameter' => 0.32,),
  'boundary:administrative:9' => array('label'=>'City District','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,),
  'boundary:administrative:10' => array('label'=>'Suburb','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,),
  'boundary:administrative:11' => array('label'=>'Neighbourhood','frequency'=>0,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,),
- 'place:city' => array('label'=>'City','frequency'=>66,'icon'=>'poi_place_city','defzoom'=>12, 'defdiameter' => 0.32,),
- 'place:country' => array('label'=>'Country','frequency'=>0,'icon'=>'poi_boundary_administrative','defzoom'=>6, 'defdiameter' => 15,),
- 'place:state' => array('label'=>'State','frequency'=>0,'icon'=>'poi_boundary_administrative','defzoom'=>8, 'defdiameter' => 5.12,),
  'place:region' => array('label'=>'State','frequency'=>0,'icon'=>'poi_boundary_administrative','defzoom'=>8, 'defdiameter' => 5.12,),
  'place:island' => array('label'=>'Island','frequency'=>288,'icon'=>'','defzoom'=>11, 'defdiameter' => 0.64,),
- 'place:county' => array('label'=>'County','frequency'=>108,'icon'=>'poi_boundary_administrative','defzoom'=>10, 'defdiameter' => 1.28,),
  'boundary:administrative' => array('label'=>'Administrative','frequency'=>413,'icon'=>'poi_boundary_administrative', 'defdiameter' => 0.32,),
  'place:town' => array('label'=>'Town','frequency'=>1497,'icon'=>'poi_place_town','defzoom'=>14, 'defdiameter' => 0.08,),
  'place:village' => array('label'=>'Village','frequency'=>11230,'icon'=>'poi_place_village','defzoom'=>15, 'defdiameter' => 0.04,),
index cd567385e50628a36ed08af438ac820907ea8b5a..8c92919c85086c782a4062ba35c4171fcbf5da51 100755 (executable)
                                                // Must have a location term
                                                if (!sizeof($aSearch['aName']) && !sizeof($aSearch['aAddress']) && !$aSearch['fLon'])
                                                {
-                                                       if (!$bBoundingBoxSearch && !$aSearch['fLon']) continue;
-                                                       if (!$aSearch['sClass']) continue;
-                                                       if (CONST_Debug) var_dump('<hr>',$aSearch);
-                                                       if (CONST_Debug) _debugDumpGroupedSearches(array($iGroupedRank => array($aSearch)), $aValidTokens);     
-
-                                                       $sSQL = "select count(*) from pg_tables where tablename = 'place_classtype_".$aSearch['sClass']."_".$aSearch['sType']."'";
-                                                       if ($oDB->getOne($sSQL))
+                                                       if ($aSearch['sCountryCode'] && !$aSearch['sClass'])
+                                                       {
+                                                               $sSQL = "select place_id from placex where country_code='".$aSearch['sCountryCode']."' and rank_search = 4 order by st_area(geometry) desc limit 1";
+                                                               $aPlaceIDs = $oDB->getCol($sSQL);
+                                                       }
+                                                       else
                                                        {
+                                                               if (!$bBoundingBoxSearch && !$aSearch['fLon']) continue;
+                                                               if (!$aSearch['sClass']) continue;
+                                                               if (CONST_Debug) var_dump('<hr>',$aSearch);
+                                                               if (CONST_Debug) _debugDumpGroupedSearches(array($iGroupedRank => array($aSearch)), $aValidTokens);     
+
+                                                               $sSQL = "select count(*) from pg_tables where tablename = 'place_classtype_".$aSearch['sClass']."_".$aSearch['sType']."'";
+                                                               if ($oDB->getOne($sSQL))
+                                                               {
                                                                $sSQL = "select place_id from place_classtype_".$aSearch['sClass']."_".$aSearch['sType'];                                                               
                                                                $sSQL .= " where st_contains($sViewboxSmallSQL, centroid)";
                                                                if ($sViewboxCentreSQL) $sSQL .= " order by st_distance($sViewboxCentreSQL, centroid) asc";
                                                                if (CONST_Debug) var_dump($sSQL);
                                                                $aPlaceIDs = $oDB->getCol($sSQL);
                                                        }
+                                                       }
                                                }
                                                else
                                                {
                                                $sOrderSQL .= 'when min(place_id) = '.$iPlaceID.' then '.$iOrder.' ';
                                        }
                                        $sOrderSQL .= ' ELSE 10000000 END';
-                                       $sSQL = "select osm_type,osm_id,class,type,rank_search,rank_address,min(place_id) as place_id,country_code,";
+                                       $sSQL = "select osm_type,osm_id,class,type,admin_level,rank_search,rank_address,min(place_id) as place_id,country_code,";
                                        $sSQL .= "get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
                                        $sSQL .= "get_name_by_language(name, $sLanguagePrefArraySQL) as placename,";
                                        $sSQL .= "get_name_by_language(name, ARRAY['ref']) as ref,";
                                        $sSQL .= "avg(ST_X(ST_Centroid(geometry))) as lon,avg(ST_Y(ST_Centroid(geometry))) as lat, ";
                                        $sSQL .= $sOrderSQL." as porder ";
                                        $sSQL .= "from placex where place_id in ($sPlaceIDs) ";
-                                       $sSQL .= "group by osm_type,osm_id,class,type,rank_search,rank_address,country_code";
+                                       $sSQL .= "group by osm_type,osm_id,class,type,admin_level,rank_search,rank_address,country_code";
                                        if (!$bDeDupe) $sSQL .= ",place_id";
                                        $sSQL .= ",get_address_by_language(place_id, $sLanguagePrefArraySQL) ";
                                        $sSQL .= ",get_name_by_language(name, $sLanguagePrefArraySQL) ";
                                        $sSQL .= ",get_name_by_language(name, ARRAY['ref']) ";
                                        $sSQL .= " union ";
-                                       $sSQL .= "select 'T' as osm_type,place_id as osm_id,'place' as class,'house' as type,30 as rank_search,30 as rank_address,min(place_id) as place_id,'us' as country_code,";
+                                       $sSQL .= "select 'T' as osm_type,place_id as osm_id,'place' as class,'house' as type,null as admin_level,30 as rank_search,30 as rank_address,min(place_id) as place_id,'us' as country_code,";
                                        $sSQL .= "get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
                                        $sSQL .= "null as placename,";
                                        $sSQL .= "null as ref,";
                                        $sSQL .= "group by place_id";
                                        if (!$bDeDupe) $sSQL .= ",place_id";
                                        $sSQL .= " union ";
-                                       $sSQL .= "select 'T' as osm_type,place_id as osm_id,'place' as class,'house' as type,30 as rank_search,30 as rank_address,min(place_id) as place_id,'us' as country_code,";
+                                       $sSQL .= "select 'T' as osm_type,place_id as osm_id,'place' as class,'house' as type,null as admin_level,30 as rank_search,30 as rank_address,min(place_id) as place_id,'us' as country_code,";
                                        $sSQL .= "get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
                                        $sSQL .= "null as placename,";
                                        $sSQL .= "null as ref,";
 //exit;
                }
 
-               if (isset($aClassType[$aResult['class'].':'.$aResult['type']]['importance']) 
+//if (CONST_Debug) var_dump($aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']);
+
+               if (isset($aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['importance']) 
+                       && $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['importance'])
+               {
+                       $aResult['importance'] = $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['importance'];
+               }
+               elseif (isset($aClassType[$aResult['class'].':'.$aResult['type']]['importance']) 
                        && $aClassType[$aResult['class'].':'.$aResult['type']]['importance'])
                {
                        $aResult['importance'] = $aClassType[$aResult['class'].':'.$aResult['type']]['importance'];