X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/c48fb88e6b4020e960ccb656cb0741ab5f2fec74..8e0ffde3e0a403d289b91ad720444fd94f3ae210:/lib/Geocode.php
diff --git a/lib/Geocode.php b/lib/Geocode.php
index c6341829..58bc3bfc 100644
--- a/lib/Geocode.php
+++ b/lib/Geocode.php
@@ -2,8 +2,10 @@
namespace Nominatim;
+require_once(CONST_BasePath.'/lib/NearPoint.php');
require_once(CONST_BasePath.'/lib/PlaceLookup.php');
require_once(CONST_BasePath.'/lib/ReverseGeocode.php');
+require_once(CONST_BasePath.'/lib/SearchDescription.php');
class Geocode
{
@@ -32,7 +34,6 @@ class Geocode
protected $bFallback = false;
protected $aCountryCodes = false;
- protected $aNearPoint = false;
protected $bBoundedSearch = false;
protected $aViewBox = false;
@@ -51,10 +52,22 @@ class Geocode
protected $sQuery = false;
protected $aStructuredQuery = false;
+ protected $oNormalizer = null;
+
public function __construct(&$oDB)
{
$this->oDB =& $oDB;
+ $this->oNormalizer = \Transliterator::createFromRules(CONST_Term_Normalization_Rules);
+ }
+
+ private function normTerm($sTerm)
+ {
+ if ($this->oNormalizer === null) {
+ return $sTerm;
+ }
+
+ return $this->oNormalizer->transliterate($sTerm);
}
public function setReverseInPlan($bReverse)
@@ -67,19 +80,45 @@ class Geocode
$this->aLangPrefOrder = $aLangPref;
}
- public function getIncludeAddressDetails()
+ public function getMoreUrlParams()
{
- return $this->bIncludeAddressDetails;
- }
+ if ($this->aStructuredQuery) {
+ $aParams = $this->aStructuredQuery;
+ } else {
+ $aParams = array('q' => $this->sQuery);
+ }
- public function getIncludeExtraTags()
- {
- return $this->bIncludeExtraTags;
- }
+ if ($this->aExcludePlaceIDs) {
+ $aParams['exclude_place_ids'] = implode(',', $this->aExcludePlaceIDs);
+ }
- public function getIncludeNameDetails()
- {
- return $this->bIncludeNameDetails;
+ if ($this->bIncludeAddressDetails) $aParams['addressdetails'] = '1';
+ if ($this->bIncludeExtraTags) $aParams['extratags'] = '1';
+ if ($this->bIncludeNameDetails) $aParams['namedetails'] = '1';
+
+ if ($this->bIncludePolygonAsPoints) $aParams['polygon'] = '1';
+ if ($this->bIncludePolygonAsText) $aParams['polygon_text'] = '1';
+ if ($this->bIncludePolygonAsGeoJSON) $aParams['polygon_geojson'] = '1';
+ if ($this->bIncludePolygonAsKML) $aParams['polygon_kml'] = '1';
+ if ($this->bIncludePolygonAsSVG) $aParams['polygon_svg'] = '1';
+
+ if ($this->fPolygonSimplificationThreshold > 0.0) {
+ $aParams['polygon_threshold'] = $this->fPolygonSimplificationThreshold;
+ }
+
+ if ($this->bBoundedSearch) $aParams['bounded'] = '1';
+ if (!$this->bDeDupe) $aParams['dedupe'] = '0';
+
+ if ($this->aCountryCodes) {
+ $aParams['countrycodes'] = implode(',', $this->aCountryCodes);
+ }
+
+ if ($this->aViewBox) {
+ $aParams['viewbox'] = $this->aViewBox[0].','.$this->aViewBox[3]
+ .','.$this->aViewBox[2].','.$this->aViewBox[1];
+ }
+
+ return $aParams;
}
public function setIncludePolygonAsPoints($b = true)
@@ -121,23 +160,6 @@ class Geocode
$this->iLimit = $iLimit + min($iLimit, 10);
}
- public function getExcludedPlaceIDs()
- {
- return $this->aExcludePlaceIDs;
- }
-
-
- public function getCountryCodes()
- {
- return $this->aCountryCodes;
- }
-
- public function getViewBoxString()
- {
- if (!$this->aViewBox) return null;
- return $this->aViewBox[0].','.$this->aViewBox[3].','.$this->aViewBox[2].','.$this->aViewBox[1];
- }
-
public function setFeatureType($sFeatureType)
{
switch ($sFeatureType) {
@@ -221,11 +243,6 @@ class Geocode
);
}
- public function setNearPoint($aNearPoint, $fRadiusDeg = 0.1)
- {
- $this->aNearPoint = array((float)$aNearPoint[0], (float)$aNearPoint[1], (float)$fRadiusDeg);
- }
-
public function setQuery($sQueryString)
{
$this->sQuery = $sQueryString;
@@ -288,7 +305,7 @@ class Geocode
$aViewbox = $oParams->getStringList('viewboxlbrt');
if ($aViewbox) {
if (count($aViewbox) != 4) {
- userError("Bad parmater 'viewbox'. Expected 4 coordinates.");
+ userError("Bad parmater 'viewboxlbrt'. Expected 4 coordinates.");
}
$this->setViewbox($aViewbox);
} else {
@@ -297,12 +314,7 @@ class Geocode
if (count($aViewbox) != 4) {
userError("Bad parmater 'viewbox'. Expected 4 coordinates.");
}
- $this->setViewBox(array(
- $aViewbox[0],
- $aViewbox[3],
- $aViewbox[2],
- $aViewbox[1]
- ));
+ $this->setViewBox($aViewbox);
} else {
$aRoute = $oParams->getStringList('route');
$fRouteWidth = $oParams->getFloat('routewidth');
@@ -346,7 +358,7 @@ class Geocode
return true;
}
- public function setStructuredQuery($sAmentiy = false, $sStreet = false, $sCity = false, $sCounty = false, $sState = false, $sCountry = false, $sPostalCode = false)
+ public function setStructuredQuery($sAmenity = false, $sStreet = false, $sCity = false, $sCounty = false, $sState = false, $sCountry = false, $sPostalCode = false)
{
$this->sQuery = false;
@@ -356,9 +368,9 @@ class Geocode
$this->aAddressRankList = array();
$this->aStructuredQuery = array();
- $this->sAllowedTypesSQLList = '';
+ $this->sAllowedTypesSQLList = false;
- $this->loadStructuredAddressElement($sAmentiy, 'amenity', 26, 30, false);
+ $this->loadStructuredAddressElement($sAmenity, 'amenity', 26, 30, false);
$this->loadStructuredAddressElement($sStreet, 'street', 26, 30, false);
$this->loadStructuredAddressElement($sCity, 'city', 14, 24, false);
$this->loadStructuredAddressElement($sCounty, 'county', 9, 13, false);
@@ -369,7 +381,7 @@ class Geocode
if (sizeof($this->aStructuredQuery) > 0) {
$this->sQuery = join(', ', $this->aStructuredQuery);
if ($this->iMaxAddressRank < 30) {
- $sAllowedTypesSQLList = '(\'place\',\'boundary\')';
+ $this->sAllowedTypesSQLList = '(\'place\',\'boundary\')';
}
}
}
@@ -400,14 +412,23 @@ class Geocode
//$aPlaceIDs is an array with key: placeID and value: tiger-housenumber, if found, else -1
if (sizeof($aPlaceIDs) == 0) return array();
- $sLanguagePrefArraySQL = "ARRAY[".join(',', array_map("getDBQuoted", $this->aLangPrefOrder))."]";
+ $sLanguagePrefArraySQL = getArraySQL(
+ array_map("getDBQuoted", $this->aLangPrefOrder)
+ );
// Get the details for display (is this a redundant extra step?)
$sPlaceIDs = join(',', array_keys($aPlaceIDs));
$sImportanceSQL = '';
- if ($this->sViewboxSmallSQL) $sImportanceSQL .= " CASE WHEN ST_Contains($this->sViewboxSmallSQL, ST_Collect(centroid)) THEN 1 ELSE 0.75 END * ";
- if ($this->sViewboxLargeSQL) $sImportanceSQL .= " CASE WHEN ST_Contains($this->sViewboxLargeSQL, ST_Collect(centroid)) THEN 1 ELSE 0.75 END * ";
+ $sImportanceSQLGeom = '';
+ if ($this->sViewboxSmallSQL) {
+ $sImportanceSQL .= " CASE WHEN ST_Contains($this->sViewboxSmallSQL, ST_Collect(centroid)) THEN 1 ELSE 0.75 END * ";
+ $sImportanceSQLGeom .= " CASE WHEN ST_Contains($this->sViewboxSmallSQL, geometry) THEN 1 ELSE 0.75 END * ";
+ }
+ if ($this->sViewboxLargeSQL) {
+ $sImportanceSQL .= " CASE WHEN ST_Contains($this->sViewboxLargeSQL, ST_Collect(centroid)) THEN 1 ELSE 0.75 END * ";
+ $sImportanceSQLGeom .= " CASE WHEN ST_Contains($this->sViewboxLargeSQL, geometry) THEN 1 ELSE 0.75 END * ";
+ }
$sSQL = "SELECT ";
$sSQL .= " osm_type,";
@@ -419,7 +440,7 @@ class Geocode
$sSQL .= " rank_address,";
$sSQL .= " min(place_id) AS place_id, ";
$sSQL .= " min(parent_place_id) AS parent_place_id, ";
- $sSQL .= " calculated_country_code AS country_code, ";
+ $sSQL .= " country_code, ";
$sSQL .= " get_address_by_language(place_id, -1, $sLanguagePrefArraySQL) AS langaddress,";
$sSQL .= " get_name_by_language(name, $sLanguagePrefArraySQL) AS placename,";
$sSQL .= " get_name_by_language(name, ARRAY['ref']) AS ref,";
@@ -462,7 +483,7 @@ class Geocode
$sSQL .= " admin_level, ";
$sSQL .= " rank_search, ";
$sSQL .= " rank_address, ";
- $sSQL .= " calculated_country_code, ";
+ $sSQL .= " country_code, ";
$sSQL .= " importance, ";
if (!$this->bDeDupe) $sSQL .= "place_id,";
$sSQL .= " langaddress, ";
@@ -472,6 +493,35 @@ class Geocode
if ($this->bIncludeNameDetails) $sSQL .= "name, ";
$sSQL .= " extratags->'place' ";
+ // postcode table
+ $sSQL .= "UNION ";
+ $sSQL .= "SELECT";
+ $sSQL .= " 'P' as osm_type,";
+ $sSQL .= " (SELECT osm_id from placex p WHERE p.place_id = lp.parent_place_id) as osm_id,";
+ $sSQL .= " 'place' as class, 'postcode' as type,";
+ $sSQL .= " null as admin_level, rank_search, rank_address,";
+ $sSQL .= " place_id, parent_place_id, country_code,";
+ $sSQL .= " get_address_by_language(place_id, -1, $sLanguagePrefArraySQL) AS langaddress,";
+ $sSQL .= " postcode as placename,";
+ $sSQL .= " postcode as ref,";
+ if ($this->bIncludeExtraTags) $sSQL .= "null AS extra,";
+ if ($this->bIncludeNameDetails) $sSQL .= "null AS names,";
+ $sSQL .= " ST_x(st_centroid(geometry)) AS lon, ST_y(st_centroid(geometry)) AS lat,";
+ $sSQL .= $sImportanceSQLGeom."(0.75-(rank_search::float/40)) AS importance, ";
+ $sSQL .= " (";
+ $sSQL .= " SELECT max(p.importance*(p.rank_address+2))";
+ $sSQL .= " FROM ";
+ $sSQL .= " place_addressline s, ";
+ $sSQL .= " placex p";
+ $sSQL .= " WHERE s.place_id = lp.parent_place_id";
+ $sSQL .= " AND p.place_id = s.address_place_id ";
+ $sSQL .= " AND s.isaddress";
+ $sSQL .= " AND p.importance is not null";
+ $sSQL .= " ) AS addressimportance, ";
+ $sSQL .= " null AS extra_place ";
+ $sSQL .= "FROM location_postcode lp";
+ $sSQL .= " WHERE place_id in ($sPlaceIDs) ";
+
if (30 >= $this->iMinAddressRank && 30 <= $this->iMaxAddressRank) {
// only Tiger housenumbers and interpolation lines need to be interpolated, because they are saved as lines
// with start- and endnumber, the common osm housenumbers are usually saved as points
@@ -547,7 +597,7 @@ class Geocode
$sSQL .= " 30 AS rank_address, ";
$sSQL .= " min(place_id) as place_id, ";
$sSQL .= " min(parent_place_id) AS parent_place_id, ";
- $sSQL .= " calculated_country_code AS country_code, ";
+ $sSQL .= " country_code, ";
$sSQL .= " get_address_by_language(place_id, housenumber_for_place, $sLanguagePrefArraySQL) AS langaddress, ";
$sSQL .= " null AS placename, ";
$sSQL .= " null AS ref, ";
@@ -572,7 +622,7 @@ class Geocode
$sSQL .= " SELECT ";
$sSQL .= " osm_id, ";
$sSQL .= " place_id, ";
- $sSQL .= " calculated_country_code, ";
+ $sSQL .= " country_code, ";
$sSQL .= " CASE "; // interpolate the housenumbers here
$sSQL .= " WHEN startnumber != endnumber ";
$sSQL .= " THEN ST_LineInterpolatePoint(linegeo, (housenumber_for_place-startnumber::float)/(endnumber-startnumber)::float) ";
@@ -591,7 +641,7 @@ class Geocode
$sSQL .= " osm_id, ";
$sSQL .= " place_id, ";
$sSQL .= " housenumber_for_place, ";
- $sSQL .= " calculated_country_code "; //is this group by really needed?, place_id + housenumber (in combination) are unique
+ $sSQL .= " country_code "; //is this group by really needed?, place_id + housenumber (in combination) are unique
if (!$this->bDeDupe) $sSQL .= ", place_id ";
if (CONST_Use_Aux_Location_data) {
@@ -649,7 +699,7 @@ class Geocode
return $aSearchResults;
}
- public function getGroupedSearches($aSearches, $aPhraseTypes, $aPhrases, $aValidTokens, $aWordFrequencyScores, $bStructuredPhrases)
+ public function getGroupedSearches($aSearches, $aPhraseTypes, $aPhrases, $aValidTokens, $aWordFrequencyScores, $bStructuredPhrases, $sNormQuery)
{
/*
Calculate all searches using aValidTokens i.e.
@@ -662,12 +712,17 @@ class Geocode
Score how good the search is so they can be ordered
*/
- foreach ($aPhrases as $iPhrase => $sPhrase) {
+ $iGlobalRank = 0;
+
+ foreach ($aPhrases as $iPhrase => $aPhrase) {
$aNewPhraseSearches = array();
- if ($bStructuredPhrases) $sPhraseType = $aPhraseTypes[$iPhrase];
- else $sPhraseType = '';
+ if ($bStructuredPhrases) {
+ $sPhraseType = $aPhraseTypes[$iPhrase];
+ } else {
+ $sPhraseType = '';
+ }
- foreach ($aPhrases[$iPhrase]['wordsets'] as $iWordSet => $aWordset) {
+ foreach ($aPhrase['wordsets'] as $iWordSet => $aWordset) {
// Too many permutations - too expensive
if ($iWordSet > 120) break;
@@ -678,165 +733,72 @@ class Geocode
//echo "
$sToken";
$aNewWordsetSearches = array();
- foreach ($aWordsetSearches as $aCurrentSearch) {
+ foreach ($aWordsetSearches as $oCurrentSearch) {
//echo "";
- //var_dump($aCurrentSearch);
+ //var_dump($oCurrentSearch);
//echo "";
// If the token is valid
if (isset($aValidTokens[' '.$sToken])) {
foreach ($aValidTokens[' '.$sToken] as $aSearchTerm) {
- $aSearch = $aCurrentSearch;
- $aSearch['iSearchRank']++;
- if (($sPhraseType == '' || $sPhraseType == 'country') && !empty($aSearchTerm['country_code']) && $aSearchTerm['country_code'] != '0') {
- if ($aSearch['sCountryCode'] === false) {
- $aSearch['sCountryCode'] = strtolower($aSearchTerm['country_code']);
- // Country is almost always at the end of the string - increase score for finding it anywhere else (optimisation)
- if (($iToken+1 != sizeof($aWordset) || $iPhrase+1 != sizeof($aPhrases))) {
- $aSearch['iSearchRank'] += 5;
- }
- if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
- }
- } elseif (isset($aSearchTerm['lat']) && $aSearchTerm['lat'] !== '' && $aSearchTerm['lat'] !== null) {
- if ($aSearch['fLat'] === '') {
- $aSearch['fLat'] = $aSearchTerm['lat'];
- $aSearch['fLon'] = $aSearchTerm['lon'];
- $aSearch['fRadius'] = $aSearchTerm['radius'];
- if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
- }
- } elseif ($sPhraseType == 'postalcode') {
- // We need to try the case where the postal code is the primary element (i.e. no way to tell if it is (postalcode, city) OR (city, postalcode) so try both
- if (isset($aSearchTerm['word_id']) && $aSearchTerm['word_id']) {
- // If we already have a name try putting the postcode first
- if (sizeof($aSearch['aName'])) {
- $aNewSearch = $aSearch;
- $aNewSearch['aAddress'] = array_merge($aNewSearch['aAddress'], $aNewSearch['aName']);
- $aNewSearch['aName'] = array();
- $aNewSearch['aName'][$aSearchTerm['word_id']] = $aSearchTerm['word_id'];
- if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aNewSearch;
- }
-
- if (sizeof($aSearch['aName'])) {
- if ((!$bStructuredPhrases || $iPhrase > 0) && $sPhraseType != 'country' && (!isset($aValidTokens[$sToken]) || strpos($sToken, ' ') !== false)) {
- $aSearch['aAddress'][$aSearchTerm['word_id']] = $aSearchTerm['word_id'];
- } else {
- $aCurrentSearch['aFullNameAddress'][$aSearchTerm['word_id']] = $aSearchTerm['word_id'];
- $aSearch['iSearchRank'] += 1000; // skip;
- }
- } else {
- $aSearch['aName'][$aSearchTerm['word_id']] = $aSearchTerm['word_id'];
- //$aSearch['iNamePhrase'] = $iPhrase;
- }
- if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
- }
- } elseif (($sPhraseType == '' || $sPhraseType == 'street') && $aSearchTerm['class'] == 'place' && $aSearchTerm['type'] == 'house') {
- if ($aSearch['sHouseNumber'] === '') {
- $aSearch['sHouseNumber'] = $sToken;
- // sanity check: if the housenumber is not mainly made
- // up of numbers, add a penalty
- if (preg_match_all("/[^0-9]/", $sToken, $aMatches) > 2) $aSearch['iSearchRank']++;
- // also housenumbers should appear in the first or second phrase
- if ($iPhrase > 1) $aSearch['iSearchRank'] += 1;
- if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
- /*
- // Fall back to not searching for this item (better than nothing)
- $aSearch = $aCurrentSearch;
- $aSearch['iSearchRank'] += 1;
- if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
- */
- }
- } elseif ($sPhraseType == '' && $aSearchTerm['class'] !== '' && $aSearchTerm['class'] !== null) {
- if ($aSearch['sClass'] === '') {
- $aSearch['sOperator'] = $aSearchTerm['operator'];
- $aSearch['sClass'] = $aSearchTerm['class'];
- $aSearch['sType'] = $aSearchTerm['type'];
- if (sizeof($aSearch['aName'])) $aSearch['sOperator'] = 'name';
- else $aSearch['sOperator'] = 'near'; // near = in for the moment
- if (strlen($aSearchTerm['operator']) == 0) $aSearch['iSearchRank'] += 1;
-
- if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
- }
- } elseif (isset($aSearchTerm['word_id']) && $aSearchTerm['word_id']) {
- if (sizeof($aSearch['aName'])) {
- if ((!$bStructuredPhrases || $iPhrase > 0) && $sPhraseType != 'country' && (!isset($aValidTokens[$sToken]) || strpos($sToken, ' ') !== false)) {
- $aSearch['aAddress'][$aSearchTerm['word_id']] = $aSearchTerm['word_id'];
- } else {
- $aCurrentSearch['aFullNameAddress'][$aSearchTerm['word_id']] = $aSearchTerm['word_id'];
- $aSearch['iSearchRank'] += 1000; // skip;
- }
- } else {
- $aSearch['aName'][$aSearchTerm['word_id']] = $aSearchTerm['word_id'];
- //$aSearch['iNamePhrase'] = $iPhrase;
+ // Recheck if the original word shows up in the query.
+ $bWordInQuery = false;
+ if (isset($aSearchTerm['word']) && $aSearchTerm['word']) {
+ $bWordInQuery = strpos(
+ $sNormQuery,
+ $this->normTerm($aSearchTerm['word'])
+ ) !== false;
+ }
+ $aNewSearches = $oCurrentSearch->extendWithFullTerm(
+ $aSearchTerm,
+ $bWordInQuery,
+ isset($aValidTokens[$sToken])
+ && strpos($sToken, ' ') === false,
+ $sPhraseType,
+ $iToken == 0 && $iPhrase == 0,
+ $iPhrase == 0,
+ $iToken + 1 == sizeof($aWordset)
+ && $iPhrase + 1 == sizeof($aPhrases),
+ $iGlobalRank
+ );
+
+ foreach ($aNewSearches as $oSearch) {
+ if ($oSearch->getRank() < $this->iMaxRank) {
+ $aNewWordsetSearches[] = $oSearch;
}
- if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
}
}
}
// Look for partial matches.
// Note that there is no point in adding country terms here
- // because country are omitted in the address.
+ // because country is omitted in the address.
if (isset($aValidTokens[$sToken]) && $sPhraseType != 'country') {
// Allow searching for a word - but at extra cost
foreach ($aValidTokens[$sToken] as $aSearchTerm) {
- if (isset($aSearchTerm['word_id']) && $aSearchTerm['word_id']) {
- if ((!$bStructuredPhrases || $iPhrase > 0) && sizeof($aCurrentSearch['aName']) && strpos($sToken, ' ') === false) {
- $aSearch = $aCurrentSearch;
- $aSearch['iSearchRank'] += 1;
- if ($aWordFrequencyScores[$aSearchTerm['word_id']] < CONST_Max_Word_Frequency) {
- $aSearch['aAddress'][$aSearchTerm['word_id']] = $aSearchTerm['word_id'];
- if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
- } elseif (isset($aValidTokens[' '.$sToken])) { // revert to the token version?
- $aSearch['aAddressNonSearch'][$aSearchTerm['word_id']] = $aSearchTerm['word_id'];
- $aSearch['iSearchRank'] += 1;
- if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
- foreach ($aValidTokens[' '.$sToken] as $aSearchTermToken) {
- if (empty($aSearchTermToken['country_code'])
- && empty($aSearchTermToken['lat'])
- && empty($aSearchTermToken['class'])
- ) {
- $aSearch = $aCurrentSearch;
- $aSearch['iSearchRank'] += 1;
- $aSearch['aAddress'][$aSearchTermToken['word_id']] = $aSearchTermToken['word_id'];
- if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
- }
- }
- } else {
- $aSearch['aAddressNonSearch'][$aSearchTerm['word_id']] = $aSearchTerm['word_id'];
- if (preg_match('#^[0-9]+$#', $sToken)) $aSearch['iSearchRank'] += 2;
- if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
- }
- }
-
- if (!sizeof($aCurrentSearch['aName']) || $aCurrentSearch['iNamePhrase'] == $iPhrase) {
- $aSearch = $aCurrentSearch;
- $aSearch['iSearchRank'] += 1;
- if (!sizeof($aCurrentSearch['aName'])) $aSearch['iSearchRank'] += 1;
- if (preg_match('#^[0-9]+$#', $sToken)) $aSearch['iSearchRank'] += 2;
- if ($aWordFrequencyScores[$aSearchTerm['word_id']] < CONST_Max_Word_Frequency) {
- $aSearch['aName'][$aSearchTerm['word_id']] = $aSearchTerm['word_id'];
- } else {
- $aSearch['aNameNonSearch'][$aSearchTerm['word_id']] = $aSearchTerm['word_id'];
- }
- $aSearch['iNamePhrase'] = $iPhrase;
- if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
+ $aNewSearches = $oCurrentSearch->extendWithPartialTerm(
+ $aSearchTerm,
+ $bStructuredPhrases,
+ $iPhrase,
+ $aWordFrequencyScores,
+ isset($aValidTokens[' '.$sToken]) ? $aValidTokens[' '.$sToken] : array()
+ );
+
+ foreach ($aNewSearches as $oSearch) {
+ if ($oSearch->getRank() < $this->iMaxRank) {
+ $aNewWordsetSearches[] = $oSearch;
}
}
}
- } else {
- // Allow skipping a word - but at EXTREAM cost
- //$aSearch = $aCurrentSearch;
- //$aSearch['iSearchRank']+=100;
- //$aNewWordsetSearches[] = $aSearch;
}
}
// Sort and cut
- usort($aNewWordsetSearches, 'bySearchRank');
+ usort($aNewWordsetSearches, array('Nominatim\SearchDescription', 'bySearchRank'));
$aWordsetSearches = array_slice($aNewWordsetSearches, 0, 50);
}
//var_Dump('