]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge remote-tracking branch 'upstream/master'
authorSarah Hoffmann <lonvia@denofr.de>
Tue, 6 Jun 2017 18:56:09 +0000 (20:56 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Tue, 6 Jun 2017 18:56:09 +0000 (20:56 +0200)
1  2 
lib/Geocode.php

diff --combined lib/Geocode.php
index 1c3c7a4e05542e52e0755b1bb629873911d8b4f1,80449cb631d350797d1ab2679aee2c22c4343368..b0f0c764ca50eabb387de7bbd36b124be4f08e41
@@@ -25,7 -25,7 +25,7 @@@ class Geocod
  
      protected $aExcludePlaceIDs = array();
      protected $bDeDupe = true;
 -    protected $bReverseInPlan = false;
 +    protected $bReverseInPlan = true;
  
      protected $iLimit = 20;
      protected $iFinalLimit = 10;
                          // TODO: filter out the pointless search terms (2 letter name tokens and less)
                          // they might be right - but they are just too darned expensive to run
                          if (sizeof($aSearch['aName'])) $aTerms[] = "name_vector @> ARRAY[".join($aSearch['aName'], ",")."]";
 -                        if (sizeof($aSearch['aNameNonSearch'])) $aTerms[] = "array_cat(name_vector,ARRAY[]::integer[]) @> ARRAY[".join($aSearch['aNameNonSearch'], ",")."]";
 +                        //if (sizeof($aSearch['aNameNonSearch'])) $aTerms[] = "array_cat(name_vector,ARRAY[]::integer[]) @> ARRAY[".join($aSearch['aNameNonSearch'], ",")."]";
                          if (sizeof($aSearch['aAddress']) && $aSearch['aName'] != $aSearch['aAddress']) {
                              // For infrequent name terms disable index usage for address
                              if (CONST_Search_NameOnlySearchFrequencyThreshold
                                  && sizeof($aSearch['aName']) == 1
                                  && $aWordFrequencyScores[$aSearch['aName'][reset($aSearch['aName'])]] < CONST_Search_NameOnlySearchFrequencyThreshold
                              ) {
 -                                $aTerms[] = "array_cat(nameaddress_vector,ARRAY[]::integer[]) @> ARRAY[".join(array_merge($aSearch['aAddress'], $aSearch['aAddressNonSearch']), ",")."]";
 +                                //$aTerms[] = "array_cat(nameaddress_vector,ARRAY[]::integer[]) @> ARRAY[".join(array_merge($aSearch['aAddress'], $aSearch['aAddressNonSearch']), ",")."]";
 +                                $aTerms[] = "array_cat(nameaddress_vector,ARRAY[]::integer[]) @> ARRAY[".join($aSearch['aAddress'],",")."]";
                              } else {
                                  $aTerms[] = "nameaddress_vector @> ARRAY[".join($aSearch['aAddress'], ",")."]";
 -                                if (sizeof($aSearch['aAddressNonSearch'])) {
 +                                /*if (sizeof($aSearch['aAddressNonSearch'])) {
                                      $aTerms[] = "array_cat(nameaddress_vector,ARRAY[]::integer[]) @> ARRAY[".join($aSearch['aAddressNonSearch'], ",")."]";
 -                                }
 +                                }*/
                              }
                          }
                          if ($aSearch['sCountryCode']) $aTerms[] = "country_code = '".pg_escape_string($aSearch['sCountryCode'])."'";
                              }
  
                              if (!$aSearch['sOperator'] || $aSearch['sOperator'] == 'near') { // & in
+                                 $sClassTable = 'place_classtype_'.$aSearch['sClass'].'_'.$aSearch['sType'];
                                  $sSQL = "SELECT count(*) FROM pg_tables ";
-                                 $sSQL .= "WHERE tablename = 'place_classtype_".$aSearch['sClass']."_".$aSearch['sType']."'";
+                                 $sSQL .= "WHERE tablename = '$sClassTable'";
                                  $bCacheTable = chksql($this->oDB->getOne($sSQL));
  
                                  $sSQL = "SELECT min(rank_search) FROM placex WHERE place_id in ($sPlaceIDs)";
                                              $sOrderBysSQL = "ST_Distance(st_centroid('".$sPlaceGeom."'), l.centroid)";
                                          }
  
-                                         $sSQL = "select distinct l.place_id".($sOrderBySQL?','.$sOrderBySQL:'')." from place_classtype_".$aSearch['sClass']."_".$aSearch['sType']." as l";
+                                         $sSQL = "select distinct i.place_id".($sOrderBySQL?', i.order_term':'')." from (";
+                                         $sSQL .= "select l.place_id".($sOrderBySQL?','.$sOrderBySQL.' as order_term':'')." from ".$sClassTable." as l";
                                          if ($sCountryCodesSQL) $sSQL .= " join placex as lp using (place_id)";
                                          if ($sPlaceIDs) {
                                              $sSQL .= ",placex as f where ";
                                              $sSQL .= " and l.place_id not in (".join(',', $this->aExcludePlaceIDs).")";
                                          }
                                          if ($sCountryCodesSQL) $sSQL .= " and lp.country_code in ($sCountryCodesSQL)";
-                                         if ($sOrderBySQL) $sSQL .= "order by ".$sOrderBySQL." asc";
+                                         $sSQL .= 'limit 300) i ';
+                                         if ($sOrderBySQL) $sSQL .= "order by order_term asc";
                                          if ($this->iOffset) $sSQL .= " offset $this->iOffset";
                                          $sSQL .= " limit $this->iLimit";
                                          if (CONST_Debug) var_dump($sSQL);