X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/73e737d7756dd900fc5b797561ec0a66b0d3272e..77b76ae51bc4751c02e58678e9003fa9838abcf1:/lib/Geocode.php
diff --git a/lib/Geocode.php b/lib/Geocode.php
index fbb1b4e0..faf9e770 100644
--- a/lib/Geocode.php
+++ b/lib/Geocode.php
@@ -2,9 +2,11 @@
namespace Nominatim;
-require_once(CONST_BasePath.'/lib/NearPoint.php');
require_once(CONST_BasePath.'/lib/PlaceLookup.php');
+require_once(CONST_BasePath.'/lib/Phrase.php');
require_once(CONST_BasePath.'/lib/ReverseGeocode.php');
+require_once(CONST_BasePath.'/lib/SearchDescription.php');
+require_once(CONST_BasePath.'/lib/SearchContext.php');
class Geocode
{
@@ -36,9 +38,8 @@ class Geocode
protected $bBoundedSearch = false;
protected $aViewBox = false;
- protected $sViewboxCentreSQL = false;
- protected $sViewboxSmallSQL = false;
- protected $sViewboxLargeSQL = false;
+ protected $aRoutePoints = false;
+ protected $aRouteWidth = false;
protected $iMaxRank = 20;
protected $iMinAddressRank = 0;
@@ -183,26 +184,6 @@ class Geocode
$this->iMaxAddressRank = $iMax;
}
- public function setRoute($aRoutePoints, $fRouteWidth)
- {
- $this->aViewBox = false;
-
- $this->sViewboxCentreSQL = "ST_SetSRID('LINESTRING(";
- $sSep = '';
- foreach ($aRoutePoints as $aPoint) {
- $fPoint = (float)$aPoint;
- $this->sViewboxCentreSQL .= $sSep.$fPoint;
- $sSep = ($sSep == ' ') ? ',' : ' ';
- }
- $this->sViewboxCentreSQL .= ")'::geometry,4326)";
-
- $this->sViewboxSmallSQL = 'ST_BUFFER('.$this->sViewboxCentreSQL;
- $this->sViewboxSmallSQL .= ','.($fRouteWidth/69).')';
-
- $this->sViewboxLargeSQL = 'ST_BUFFER('.$this->sViewboxCentreSQL;
- $this->sViewboxLargeSQL .= ','.($fRouteWidth/30).')';
- }
-
public function setViewbox($aViewbox)
{
$this->aViewBox = array_map('floatval', $aViewbox);
@@ -217,29 +198,6 @@ class Geocode
) {
userError("Bad parameter 'viewbox'. Not a box.");
}
-
- $fHeight = $this->aViewBox[0] - $this->aViewBox[2];
- $fWidth = $this->aViewBox[1] - $this->aViewBox[3];
- $aBigViewBox[0] = $this->aViewBox[0] + $fHeight;
- $aBigViewBox[2] = $this->aViewBox[2] - $fHeight;
- $aBigViewBox[1] = $this->aViewBox[1] + $fWidth;
- $aBigViewBox[3] = $this->aViewBox[3] - $fWidth;
-
- $this->sViewboxCentreSQL = false;
- $this->sViewboxSmallSQL = sprintf(
- 'ST_SetSRID(ST_MakeBox2D(ST_Point(%F,%F),ST_Point(%F,%F)),4326)',
- $this->aViewBox[0],
- $this->aViewBox[1],
- $this->aViewBox[2],
- $this->aViewBox[3]
- );
- $this->sViewboxLargeSQL = sprintf(
- 'ST_SetSRID(ST_MakeBox2D(ST_Point(%F,%F),ST_Point(%F,%F)),4326)',
- $aBigViewBox[0],
- $aBigViewBox[1],
- $aBigViewBox[2],
- $aBigViewBox[3]
- );
}
public function setQuery($sQueryString)
@@ -318,7 +276,8 @@ class Geocode
$aRoute = $oParams->getStringList('route');
$fRouteWidth = $oParams->getFloat('routewidth');
if ($aRoute && $fRouteWidth) {
- $this->setRoute($aRoute, $fRouteWidth);
+ $this->aRoutePoints = $aRoute;
+ $this->aRouteWidth = $fRouteWidth;
}
}
}
@@ -367,7 +326,7 @@ class Geocode
$this->aAddressRankList = array();
$this->aStructuredQuery = array();
- $this->sAllowedTypesSQLList = False;
+ $this->sAllowedTypesSQLList = false;
$this->loadStructuredAddressElement($sAmenity, 'amenity', 26, 30, false);
$this->loadStructuredAddressElement($sStreet, 'street', 26, 30, false);
@@ -406,26 +365,20 @@ class Geocode
return false;
}
- public function getDetails($aPlaceIDs)
+ public function getDetails($aPlaceIDs, $oCtx)
{
//$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 = '';
- $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 * ";
- }
+ $sImportanceSQL = $oCtx->viewboxImportanceSQL('ST_Collect(centroid)');
+ $sImportanceSQLGeom = $oCtx->viewboxImportanceSQL('geometry');
$sSQL = "SELECT ";
$sSQL .= " osm_type,";
@@ -445,17 +398,21 @@ class Geocode
if ($this->bIncludeNameDetails) $sSQL .= "hstore_to_json(name)::text AS names,";
$sSQL .= " avg(ST_X(centroid)) AS lon, ";
$sSQL .= " avg(ST_Y(centroid)) AS lat, ";
- $sSQL .= " ".$sImportanceSQL."COALESCE(importance,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 = min(CASE WHEN placex.rank_search < 28 THEN placex.place_id ELSE placex.parent_place_id END)";
- $sSQL .= " AND p.place_id = s.address_place_id ";
- $sSQL .= " AND s.isaddress ";
- $sSQL .= " AND p.importance is not null ";
- $sSQL .= " ) AS addressimportance, ";
+ $sSQL .= " COALESCE(importance,0.75-(rank_search::float/40)) $sImportanceSQL AS importance, ";
+ if ($oCtx->hasNearPoint()) {
+ $sSQL .= $oCtx->distanceSQL('ST_Collect(centroid)')." AS addressimportance,";
+ } else {
+ $sSQL .= " ( ";
+ $sSQL .= " SELECT max(p.importance*(p.rank_address+2))";
+ $sSQL .= " FROM ";
+ $sSQL .= " place_addressline s, ";
+ $sSQL .= " placex p";
+ $sSQL .= " WHERE s.place_id = min(CASE WHEN placex.rank_search < 28 THEN placex.place_id ELSE placex.parent_place_id END)";
+ $sSQL .= " AND p.place_id = s.address_place_id ";
+ $sSQL .= " AND s.isaddress ";
+ $sSQL .= " AND p.importance is not null ";
+ $sSQL .= " ) AS addressimportance, ";
+ }
$sSQL .= " (extratags->'place') AS extra_place ";
$sSQL .= " FROM placex";
$sSQL .= " WHERE place_id in ($sPlaceIDs) ";
@@ -504,17 +461,21 @@ class Geocode
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 .= " (0.75-(rank_search::float/40)) $sImportanceSQLGeom AS importance, ";
+ if ($oCtx->hasNearPoint()) {
+ $sSQL .= $oCtx->distanceSQL('geometry')." AS addressimportance,";
+ } else {
+ $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) ";
@@ -552,17 +513,21 @@ class Geocode
if ($this->bIncludeNameDetails) $sSQL .= "null AS names,";
$sSQL .= " avg(st_x(centroid)) AS lon, ";
$sSQL .= " avg(st_y(centroid)) AS lat,";
- $sSQL .= " ".$sImportanceSQL."-1.15 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 = min(blub.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 .= " -1.15".$sImportanceSQL." AS importance, ";
+ if ($oCtx->hasNearPoint()) {
+ $sSQL .= $oCtx->distanceSQL('ST_Collect(centroid)')." AS addressimportance,";
+ } else {
+ $sSQL .= " (";
+ $sSQL .= " SELECT max(p.importance*(p.rank_address+2))";
+ $sSQL .= " FROM ";
+ $sSQL .= " place_addressline s, ";
+ $sSQL .= " placex p";
+ $sSQL .= " WHERE s.place_id = min(blub.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 (";
$sSQL .= " SELECT place_id, "; // interpolate the Tiger housenumbers here
@@ -602,18 +567,22 @@ class Geocode
if ($this->bIncludeNameDetails) $sSQL .= "null AS names, ";
$sSQL .= " AVG(st_x(centroid)) AS lon, ";
$sSQL .= " AVG(st_y(centroid)) AS lat, ";
- $sSQL .= " ".$sImportanceSQL."-0.1 AS importance, "; // slightly smaller than the importance for normal houses with rank 30, which is 0
- $sSQL .= " (";
- $sSQL .= " SELECT ";
- $sSQL .= " MAX(p.importance*(p.rank_address+2)) ";
- $sSQL .= " FROM";
- $sSQL .= " place_addressline s, ";
- $sSQL .= " placex p";
- $sSQL .= " WHERE s.place_id = min(blub.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 .= " -0.1".$sImportanceSQL." AS importance, "; // slightly smaller than the importance for normal houses with rank 30, which is 0
+ if ($oCtx->hasNearPoint()) {
+ $sSQL .= $oCtx->distanceSQL('ST_Collect(centroid)')." AS addressimportance,";
+ } else {
+ $sSQL .= " (";
+ $sSQL .= " SELECT ";
+ $sSQL .= " MAX(p.importance*(p.rank_address+2)) ";
+ $sSQL .= " FROM";
+ $sSQL .= " place_addressline s, ";
+ $sSQL .= " placex p";
+ $sSQL .= " WHERE s.place_id = min(blub.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 (";
$sSQL .= " SELECT ";
@@ -661,17 +630,21 @@ class Geocode
if ($this->bIncludeNameDetails) $sSQL .= "null AS names, ";
$sSQL .= " avg(ST_X(centroid)) AS lon, ";
$sSQL .= " avg(ST_Y(centroid)) AS lat, ";
- $sSQL .= " ".$sImportanceSQL."-1.10 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 = min(location_property_aux.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 .= " -1.10".$sImportanceSQL." AS importance, ";
+ if ($oCtx->hasNearPoint()) {
+ $sSQL .= $oCtx->distanceSQL('ST_Collect(centroid)')." AS addressimportance,";
+ } else {
+ $sSQL .= " ( ";
+ $sSQL .= " SELECT max(p.importance*(p.rank_address+2))";
+ $sSQL .= " FROM ";
+ $sSQL .= " place_addressline s, ";
+ $sSQL .= " placex p";
+ $sSQL .= " WHERE s.place_id = min(location_property_aux.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_property_aux ";
$sSQL .= " WHERE place_id in ($sPlaceIDs) ";
@@ -696,7 +669,7 @@ class Geocode
return $aSearchResults;
}
- public function getGroupedSearches($aSearches, $aPhraseTypes, $aPhrases, $aValidTokens, $aWordFrequencyScores, $bStructuredPhrases, $sNormQuery)
+ public function getGroupedSearches($aSearches, $aPhrases, $aValidTokens, $bIsStructured, $sNormQuery)
{
/*
Calculate all searches using aValidTokens i.e.
@@ -711,12 +684,11 @@ class Geocode
*/
$iGlobalRank = 0;
- foreach ($aPhrases as $iPhrase => $aPhrase) {
+ foreach ($aPhrases as $iPhrase => $oPhrase) {
$aNewPhraseSearches = array();
- if ($bStructuredPhrases) $sPhraseType = $aPhraseTypes[$iPhrase];
- else $sPhraseType = '';
+ $sPhraseType = $bIsStructured ? $oPhrase->getPhraseType() : '';
- foreach ($aPhrase['wordsets'] as $iWordSet => $aWordset) {
+ foreach ($oPhrase->getWordSets() as $iWordSet => $aWordset) {
// Too many permutations - too expensive
if ($iWordSet > 120) break;
@@ -727,169 +699,71 @@ 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])) {
- // TODO variable should go into aCurrentSearch
- $bHavePostcode = false;
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;
- // If it is at the beginning, we can be almost sure that this is the wrong order
- // Increase score for all searches.
- if ($iToken == 0 && $iPhrase == 0) {
- $iGlobalRank++;
- }
- }
- } elseif (($sPhraseType == '' || $sPhraseType == 'postalcode') && $aSearchTerm['class'] == 'place' && $aSearchTerm['type'] == 'postcode') {
- // 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 ($aSearch['sPostcode'] === '' &&
- isset($aSearchTerm['word']) && $aSearchTerm['word'] && strpos($sNormQuery, $this->normTerm($aSearchTerm['word'])) !== false) {
- // If we have structured search or this is the first term,
- // make the postcode the primary search element.
- if (!$bHavePostcode && $aSearch['sOperator'] === '' && ($sPhraseType == 'postalcode' || ($iToken == 0 && $iPhrase == 0))) {
- $aNewSearch = $aSearch;
- $aNewSearch['sOperator'] = 'postcode';
- $aNewSearch['aAddress'] = array_merge($aNewSearch['aAddress'], $aNewSearch['aName']);
- $aNewSearch['aName'] = array($aSearchTerm['word_id'] => $aSearchTerm['word']);
- if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aNewSearch;
- $bHavePostcode = true;
- }
-
- // If we have a structured search or this is not the first term,
- // add the postcode as an addendum.
- if ($aSearch['sOperator'] !== 'postcode' && ($sPhraseType == 'postalcode' || sizeof($aSearch['aName']))) {
- $aSearch['sPostcode'] = $aSearchTerm['word'];
- if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
- }
- }
- } elseif (($sPhraseType == '' || $sPhraseType == 'street') && $aSearchTerm['class'] == 'place' && $aSearchTerm['type'] == 'house') {
- if ($aSearch['sHouseNumber'] === '' && $aSearch['sOperator'] !== 'postcode') {
- $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 must not appear in the middle of the address
- if ($aSearch['aAddress'] || $aSearch['aAddressNonSearch']) $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) {
- // require a normalized exact match of the term
- // if we have the normalizer version of the query
- // available
- if ($aSearch['sOperator'] === ''
- && ($sNormQuery === null || !($aSearchTerm['word'] && strpos($sNormQuery, $aSearchTerm['word']) === false))) {
- $aSearch['sClass'] = $aSearchTerm['class'];
- $aSearch['sType'] = $aSearchTerm['type'];
- if ($aSearchTerm['operator'] == '') {
- $aSearch['sOperator'] = sizeof($aSearch['aName']) ? 'name' : 'near';
- $aSearch['iSearchRank'] += 2;
- } else {
- $aSearch['sOperator'] = 'near'; // near = in for the moment
- }
-
- 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 ((!$aCurrentSearch['sPostcode'] && !$aCurrentSearch['aAddress'] && !$aCurrentSearch['aAddressNonSearch'])
- && (!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,
+ $bIsStructured,
+ $iPhrase,
+ 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('