foreach(explode(',',$aParams['exclude_place_ids']) as $iExcludedPlaceID)
{
$iExcludedPlaceID = (int)$iExcludedPlaceID;
- if ($iExcludedPlaceID) $aExcludePlaceIDs[$iExcludedPlaceID] = $iExcludedPlaceID;
+ if ($iExcludedPlaceID)
+ $aExcludePlaceIDs[$iExcludedPlaceID] = $iExcludedPlaceID;
}
- $this->aExcludePlaceIDs = $aExcludePlaceIDs;
+
+ if (isset($aExcludePlaceIDs))
+ $this->aExcludePlaceIDs = $aExcludePlaceIDs;
}
// Only certain ranks of feature
if (sizeof($aSearch['aName']))
{
- if ((!$bStructuredPhrases || $iPhrase > 0) && $sPhraseType != 'country' && (!isset($aValidTokens[$sToken]) || strlen($sToken) < 4 || strpos($sToken, ' ') !== false))
+ if ((!$bStructuredPhrases || $iPhrase > 0) && $sPhraseType != 'country' && (!isset($aValidTokens[$sToken]) || strpos($sToken, ' ') !== false))
{
$aSearch['aAddress'][$aSearchTerm['word_id']] = $aSearchTerm['word_id'];
}
{
if (sizeof($aSearch['aName']))
{
- if ((!$bStructuredPhrases || $iPhrase > 0) && $sPhraseType != 'country' && (!isset($aValidTokens[$sToken]) || strlen($sToken) < 4 || strpos($sToken, ' ') !== false))
+ if ((!$bStructuredPhrases || $iPhrase > 0) && $sPhraseType != 'country' && (!isset($aValidTokens[$sToken]) || strpos($sToken, ' ') !== false))
{
$aSearch['aAddress'][$aSearchTerm['word_id']] = $aSearchTerm['word_id'];
}
$aSearch['aAddress'][$aSearchTerm['word_id']] = $aSearchTerm['word_id'];
if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
}
- elseif (isset($aValidTokens[' '.$sToken]) && strlen($sToken) >= 4) // revert to the token version?
+ elseif (isset($aValidTokens[' '.$sToken])) // revert to the token version?
{
$aSearch['aAddressNonSearch'][$aSearchTerm['word_id']] = $aSearchTerm['word_id'];
$aSearch['iSearchRank'] += 1;
preg_match_all('/\\[([\\w ]*)\\]/u', $sQuery, $aSpecialTermsRaw, PREG_SET_ORDER);
$aSpecialTerms = array();
- if (isset($aStructuredQuery['amenity']) && $aStructuredQuery['amenity'])
+ if (isset($this->aStructuredQuery['amenity']) && $this->aStructuredQuery['amenity'])
{
- $aSpecialTermsRaw[] = array('['.$aStructuredQuery['amenity'].']', $aStructuredQuery['amenity']);
- unset($aStructuredQuery['amenity']);
+ $aSpecialTermsRaw[] = array('['.$this->aStructuredQuery['amenity'].']', $this->aStructuredQuery['amenity']);
+ unset($this->aStructuredQuery['amenity']);
}
foreach($aSpecialTermsRaw as $aSpecialTerm)
{
foreach($aDatabaseWords as $aToken)
{
// Very special case - require 2 letter country param to match the country code found
- if ($bStructuredPhrases && $aToken['country_code'] && !empty($aStructuredQuery['country'])
- && strlen($aStructuredQuery['country']) == 2 && strtolower($aStructuredQuery['country']) != $aToken['country_code'])
+ if ($bStructuredPhrases && $aToken['country_code'] && !empty($this->aStructuredQuery['country'])
+ && strlen($this->aStructuredQuery['country']) == 2 && strtolower($this->aStructuredQuery['country']) != $aToken['country_code'])
{
continue;
}
if (CONST_Debug) var_Dump($aGroupedSearches);
- if (CONST_Search_TryDroppedAddressTerms && sizeof($aStructuredQuery) > 0)
+ if (CONST_Search_TryDroppedAddressTerms && sizeof($this->aStructuredQuery) > 0)
{
$aCopyGroupedSearches = $aGroupedSearches;
foreach($aCopyGroupedSearches as $iGroup => $aSearches)
$aTerms = array();
$aOrder = array();
- if ($aSearch['sHouseNumber'])
+ if ($aSearch['sHouseNumber'] && sizeof($aSearch['aAddress']))
{
$sHouseNumberRegex = '\\\\m'.$aSearch['sHouseNumber'].'\\\\M';
$aOrder[] = "exists(select place_id from placex where parent_place_id = search_name.place_id and transliteration(housenumber) ~* E'".$sHouseNumberRegex."' limit 1) desc";
$aRecheckWords = preg_split('/\b[\s,\\-]*/u',$sQuery);
foreach($aRecheckWords as $i => $sWord)
{
- if (!$sWord) unset($aRecheckWords[$i]);
+ if (!preg_match('/\pL/', $sWord)) unset($aRecheckWords[$i]);
}
+ if (CONST_Debug) { echo '<i>Recheck words:<\i>'; var_dump($aRecheckWords); }
+
foreach($aSearchResults as $iResNum => $aResult)
{
if (CONST_Search_AreaPolygons)
// Get the bounding box and outline polygon
$sSQL = "select place_id,0 as numfeatures,st_area(geometry) as area,";
$sSQL .= "ST_Y(centroid) as centrelat,ST_X(centroid) as centrelon,";
- $sSQL .= "ST_Y(ST_PointN(ST_ExteriorRing(Box2D(geometry)),4)) as minlat,ST_Y(ST_PointN(ST_ExteriorRing(Box2D(geometry)),2)) as maxlat,";
- $sSQL .= "ST_X(ST_PointN(ST_ExteriorRing(Box2D(geometry)),1)) as minlon,ST_X(ST_PointN(ST_ExteriorRing(Box2D(geometry)),3)) as maxlon";
+ $sSQL .= "ST_YMin(geometry) as minlat,ST_YMax(geometry) as maxlat,";
+ $sSQL .= "ST_XMin(geometry) as minlon,ST_XMax(geometry) as maxlon";
if ($this->bIncludePolygonAsGeoJSON) $sSQL .= ",ST_AsGeoJSON(geometry) as asgeojson";
if ($this->bIncludePolygonAsKML) $sSQL .= ",ST_AsKML(geometry) as askml";
if ($this->bIncludePolygonAsSVG) $sSQL .= ",ST_AsSVG(geometry) as assvg";
if ($this->bIncludePolygonAsText || $this->bIncludePolygonAsPoints) $sSQL .= ",ST_AsText(geometry) as astext";
- $sSQL .= " from placex where place_id = ".$aResult['place_id'].' and st_geometrytype(Box2D(geometry)) = \'ST_Polygon\'';
+ $sSQL .= " from placex where place_id = ".$aResult['place_id'];
$aPointPolygon = $this->oDB->getRow($sSQL);
if (PEAR::IsError($aPointPolygon))
{
if ($this->bIncludePolygonAsPoints)
{
- // Translate geometary string to point array
+ // Translate geometry string to point array
if (preg_match('#POLYGON\\(\\(([- 0-9.,]+)#',$aPointPolygon['astext'],$aMatch))
{
preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/',$aMatch[1],$aPolyPoints,PREG_SET_ORDER);
if (stripos($sAddress, $sWord)!==false)
{
$iCountWords++;
- if (preg_match("/(^|,)\s*$sWord\s*(,|$)/", $sAddress)) $iCountWords += 0.1;
+ if (preg_match("/(^|,)\s*".preg_quote($sWord, '/')."\s*(,|$)/", $sAddress)) $iCountWords += 0.1;
}
}