X-Git-Url: https://git.openstreetmap.org/nominatim.git/blobdiff_plain/f78d094483da1c54ff51177cafa378406636b433..12168e3ca9421ab1d0195507919c26ce029ce155:/lib/SearchDescription.php diff --git a/lib/SearchDescription.php b/lib/SearchDescription.php index edf4d059..a1910231 100644 --- a/lib/SearchDescription.php +++ b/lib/SearchDescription.php @@ -58,7 +58,7 @@ class SearchDescription /** * Get current search rank. * - * The higher the search rank the lower the likelyhood that the + * The higher the search rank the lower the likelihood that the * search is a correct interpretation of the search query. * * @return integer Search rank. @@ -240,7 +240,7 @@ class SearchDescription $oSearch->sHouseNumber = trim($aSearchTerm['word_token']); // sanity check: if the housenumber is not mainly made // up of numbers, add a penalty - if (preg_match_all("/[^0-9]/", $oSearch->sHouseNumber, $aMatches) > 2) { + if (preg_match_all('/[^0-9]/', $oSearch->sHouseNumber, $aMatches) > 2) { $oSearch->iSearchRank++; } if (!isset($aSearchTerm['word_id'])) { @@ -262,7 +262,7 @@ class SearchDescription $iOp = Operator::NEAR; // near == in for the moment if ($aSearchTerm['operator'] == '') { - if (sizeof($this->aName)) { + if (sizeof($this->aName) || $this->oContext->isBoundedSearch()) { $iOp = Operator::NAME; } $oSearch->iSearchRank += 2; @@ -289,10 +289,14 @@ class SearchDescription $this->aFullNameAddress[$iWordID] = $iWordID; } } else { - $oSearch = clone $this; - $oSearch->iSearchRank++; - $oSearch->aName = array($iWordID => $iWordID); - $aNewSearches[] = $oSearch; + // in structured search only the first phrase can be the + // designated name + if ($sPhraseType == '' || $bFirstPhrase) { + $oSearch = clone $this; + $oSearch->iSearchRank++; + $oSearch->aName = array($iWordID => $iWordID); + $aNewSearches[] = $oSearch; + } } } @@ -326,7 +330,7 @@ class SearchDescription ) { if ($aSearchTerm['search_name_count'] + 1 < CONST_Max_Word_Frequency) { $oSearch = clone $this; - $oSearch->iSearchRank++; + $oSearch->iSearchRank += 2; $oSearch->aAddress[$iWordID] = $iWordID; $aNewSearches[] = $oSearch; } else { @@ -360,7 +364,7 @@ class SearchDescription && (!sizeof($this->aName) || $this->iNamePhrase == $iPhrase) ) { $oSearch = clone $this; - $oSearch->iSearchRank++; + $oSearch->iSearchRank += 2; if (!sizeof($this->aName)) { $oSearch->iSearchRank += 1; } @@ -450,7 +454,7 @@ class SearchDescription } if (CONST_Debug) { - echo "
Place IDs: "; + echo '
Place IDs: '; var_dump(array_keys($aResults)); } @@ -469,7 +473,7 @@ class SearchDescription } $aResults = $aNewResults; if (CONST_Debug) { - echo "
Place IDs after postcode filtering: "; + echo '
Place IDs after postcode filtering: '; var_dump(array_keys($aResults)); } } @@ -488,7 +492,7 @@ class SearchDescription if ($this->oContext->bViewboxBounded) { $sSQL .= ' AND ST_Intersects('.$this->oContext->sqlViewboxSmall.', geometry)'; } - $sSQL .= " ORDER BY st_area(geometry) DESC LIMIT 1"; + $sSQL .= ' ORDER BY st_area(geometry) DESC LIMIT 1'; if (CONST_Debug) var_dump($sSQL); @@ -543,7 +547,7 @@ class SearchDescription if ($this->oContext->sqlCountryList) { $sSQL .= ' AND country_code in '.$this->oContext->sqlCountryList; } - $sSQL .= ' ORDER BY '.$this->oContext->distanceSQL('centroid')." ASC"; + $sSQL .= ' ORDER BY '.$this->oContext->distanceSQL('centroid').' ASC'; $sSQL .= " LIMIT $iLimit"; if (CONST_Debug) var_dump($sSQL); $aDBResults = chksql($oDB->getCol($sSQL)); @@ -638,13 +642,13 @@ class SearchDescription } if ($this->sHouseNumber) { - $aTerms[] = "address_rank between 16 and 27"; + $aTerms[] = 'address_rank between 16 and 27'; } elseif (!$this->sClass || $this->iOperator == Operator::NAME) { if ($iMinAddressRank > 0) { - $aTerms[] = "address_rank >= ".$iMinAddressRank; + $aTerms[] = 'address_rank >= '.$iMinAddressRank; } if ($iMaxAddressRank < 30) { - $aTerms[] = "address_rank <= ".$iMaxAddressRank; + $aTerms[] = 'address_rank <= '.$iMaxAddressRank; } } @@ -675,7 +679,7 @@ class SearchDescription if ($this->sHouseNumber) { $sImportanceSQL = '- abs(26 - address_rank) + 3'; } else { - $sImportanceSQL = '(CASE WHEN importance = 0 OR importance IS NULL THEN 0.75-(search_rank::float/40) ELSE importance END)'; + $sImportanceSQL = '(CASE WHEN importance = 0 OR importance IS NULL THEN 0.75001-(search_rank::float/40) ELSE importance END)'; } $sImportanceSQL .= $this->oContext->viewboxImportanceSQL('centroid'); $aOrder[] = "$sImportanceSQL DESC"; @@ -710,7 +714,7 @@ class SearchDescription $aDBResults = chksql( $oDB->getAll($sSQL), - "Could not get places for search terms." + 'Could not get places for search terms.' ); foreach ($aDBResults as $aResult) { @@ -762,8 +766,8 @@ class SearchDescription $sSQL .= "interpolationtype='odd'"; } $sSQL .= " or interpolationtype='all') and "; - $sSQL .= $iHousenumber.">=startnumber and "; - $sSQL .= $iHousenumber."<=endnumber"; + $sSQL .= $iHousenumber.'>=startnumber and '; + $sSQL .= $iHousenumber.'<=endnumber'; $sSQL .= $this->oContext->excludeSQL(' AND place_id'); $sSQL .= " limit $iLimit"; @@ -801,8 +805,8 @@ class SearchDescription $sSQL .= "interpolationtype='odd'"; } $sSQL .= " or interpolationtype='all') and "; - $sSQL .= $iHousenumber.">=startnumber and "; - $sSQL .= $iHousenumber."<=endnumber"; + $sSQL .= $iHousenumber.'>=startnumber and '; + $sSQL .= $iHousenumber.'<=endnumber'; $sSQL .= $this->oContext->excludeSQL(' AND place_id'); $sSQL .= " limit $iLimit"; @@ -835,9 +839,9 @@ class SearchDescription $sSQL .= " WHERE place_id in ($sPlaceIDs)"; $sSQL .= " AND class='".$this->sClass."' "; $sSQL .= " AND type='".$this->sType."'"; - $sSQL .= " AND linked_place_id is null"; + $sSQL .= ' AND linked_place_id is null'; $sSQL .= $this->oContext->excludeSQL(' AND place_id'); - $sSQL .= " ORDER BY rank_search ASC "; + $sSQL .= ' ORDER BY rank_search ASC '; $sSQL .= " LIMIT $iLimit"; if (CONST_Debug) var_dump($sSQL); @@ -865,8 +869,8 @@ class SearchDescription $sSQL .= " WHERE place_id in ($sPlaceIDs)"; $sSQL .= " AND rank_search < $iMaxRank + 5"; $sSQL .= " AND ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon')"; - $sSQL .= " ORDER BY rank_search ASC "; - $sSQL .= " LIMIT 1"; + $sSQL .= ' ORDER BY rank_search ASC '; + $sSQL .= ' LIMIT 1'; if (CONST_Debug) var_dump($sSQL); $sPlaceGeom = chksql($oDB->getOne($sSQL)); } @@ -892,7 +896,7 @@ class SearchDescription if ($this->oContext->hasNearPoint()) { $sOrderBySQL = $this->oContext->distanceSQL('l.centroid'); } elseif ($sPlaceIDs) { - $sOrderBySQL = "ST_Distance(l.centroid, f.geometry)"; + $sOrderBySQL = 'ST_Distance(l.centroid, f.geometry)'; } elseif ($sPlaceGeom) { $sOrderBySQL = "ST_Distance(st_centroid('".$sPlaceGeom."'), l.centroid)"; } @@ -908,7 +912,7 @@ class SearchDescription $sSQL .= ' from '.$sClassTable.' as l'; if ($sPlaceIDs) { - $sSQL .= ",placex as f WHERE "; + $sSQL .= ',placex as f WHERE '; $sSQL .= "f.place_id in ($sPlaceIDs) "; $sSQL .= " AND ST_DWithin(l.centroid, f.centroid, $fRange)"; } elseif ($sPlaceGeom) { @@ -936,7 +940,7 @@ class SearchDescription if ($this->oContext->hasNearPoint()) { $sOrderBySQL = $this->oContext->distanceSQL('l.geometry'); } else { - $sOrderBySQL = "ST_Distance(l.geometry, f.geometry)"; + $sOrderBySQL = 'ST_Distance(l.geometry, f.geometry)'; } $sSQL = 'SELECT distinct l.place_id'; @@ -950,7 +954,7 @@ class SearchDescription $sSQL .= " AND l.type='".$this->sType."'"; $sSQL .= $this->oContext->excludeSQL(' AND l.place_id'); if ($sOrderBySQL) { - $sSQL .= "ORDER BY orderterm ASC"; + $sSQL .= 'ORDER BY orderterm ASC'; } $sSQL .= " limit $iLimit"; @@ -1005,19 +1009,19 @@ class SearchDescription return $aWordIDs[$k]; }; - echo ""; + echo ''; echo "$this->iSearchRank"; - echo "".join(', ', array_map($kf, $this->aName)).""; - echo "".join(', ', array_map($kf, $this->aNameNonSearch)).""; - echo "".join(', ', array_map($kf, $this->aAddress)).""; - echo "".join(', ', array_map($kf, $this->aAddressNonSearch)).""; - echo "".$this->sCountryCode.""; - echo "".Operator::toString($this->iOperator).""; - echo "".$this->sClass.""; - echo "".$this->sType.""; - echo "".$this->sPostcode.""; - echo "".$this->sHouseNumber.""; - - echo ""; + echo ''.join(', ', array_map($kf, $this->aName)).''; + echo ''.join(', ', array_map($kf, $this->aNameNonSearch)).''; + echo ''.join(', ', array_map($kf, $this->aAddress)).''; + echo ''.join(', ', array_map($kf, $this->aAddressNonSearch)).''; + echo ''.$this->sCountryCode.''; + echo ''.Operator::toString($this->iOperator).''; + echo ''.$this->sClass.''; + echo ''.$this->sType.''; + echo ''.$this->sPostcode.''; + echo ''.$this->sHouseNumber.''; + + echo ''; } }