namespace Nominatim;
-/**
- * Operators describing special searches.
- */
-abstract class Operator
-{
- /// No operator selected.
- const NONE = 0;
- /// Search for POI of the given type.
- const TYPE = 1;
- /// Search for POIs near the given place.
- const NEAR = 2;
- /// Search for POIS in the given place.
- const IN = 3;
- /// Search for POIS named as given.
- const NAME = 4;
- /// Search for postcodes.
- const POSTCODE = 5;
-}
+require_once(CONST_BasePath.'/lib/SpecialSearchOperator.php');
/**
* Description of a single interpretation of a search query.
/// Index of phrase currently processed
private $iNamePhrase = -1;
+
public function getRank()
{
return $this->iSearchRank;
return $this->sPostcode;
}
- /**
- * Set the geographic search radius.
- */
public function setNear(&$oNearPoint)
{
$this->oNearPoint = $oNearPoint;
$this->sType = $sType;
}
- /**
- * Check if name or address for the search are specified.
- */
public function isNamedSearch()
{
return sizeof($this->aName) > 0 || sizeof($this->aAddress) > 0;
}
- /**
- * Check if only a country is requested.
- */
public function isCountrySearch()
{
return $this->sCountryCode && sizeof($this->aName) == 0
&& !$this->iOperator && !$this->oNearPoint;
}
- /**
- * Check if a search near a geographic location is requested.
- */
public function isNearSearch()
{
return (bool) $this->oNearPoint;
return $this->iOperator != Operator::NONE;
}
- /**
- * Extract special terms from the query, amend the search
- * and return the shortended query.
- *
- * Only the first special term found will be used but all will
- * be removed from the query.
- */
public function extractKeyValuePairs($sQuery)
{
// Search for terms of kind [<key>=<value>].
/////////// Search building functions
+
public function extendWithFullTerm($aSearchTerm, $bWordInQuery, $bHasPartial, $sPhraseType, $bFirstToken, $bFirstPhrase, $bLastToken, &$iGlobalRank)
{
$aNewSearches = array();
}
$oSearch->setPoiSearch($iOp, $aSearchTerm['class'], $aSearchTerm['type']);
- $aNewWordsetSearches[] = $oSearch;
+ $aNewSearches[] = $oSearch;
}
} elseif (isset($aSearchTerm['word_id']) && $aSearchTerm['word_id']) {
$iWordID = $aSearchTerm['word_id'];
$oSearch->iSearchRank++;
$oSearch->aAddress[$iWordID] = $iWordID;
$aNewSearches[] = $oSearch;
- }
- else {
+ } else {
$this->aFullNameAddress[$iWordID] = $iWordID;
}
} else {
$aNewSearches[] = $oSearch;
}
}
- }
+ }
}
if ((!$this->sPostcode && !$this->aAddress && !$this->aAddressNonSearch)
/////////// Query functions
+
public function queryCountry(&$oDB, $sViewboxSQL)
{
$sSQL = 'SELECT place_id FROM placex ';
public function queryPostcode(&$oDB, $sCountryList, $iLimit)
{
- $sSQL = 'SELECT p.place_id FROM location_postcode p ';
+ $sSQL = 'SELECT p.place_id FROM location_postcode p ';
if (sizeof($this->aAddress)) {
$sSQL .= ', search_name s ';
$sSQL .= 'WHERE ';
}
- $sSQL .= "p.postcode = '".pg_escape_string(reset($this->$aName))."'";
+ $sSQL .= "p.postcode = '".pg_escape_string(reset($this->aName))."'";
$sCountryTerm = $this->countryCodeSQL('p.country_code', $sCountryList);
if ($sCountryTerm) {
- $sSQL .= ' AND '.$sCountyTerm;
+ $sSQL .= ' AND '.$sCountryTerm;
}
$sSQL .= " LIMIT $iLimit";
}
if ($sViewboxSmall) {
- $aTerms[] = 'centroid && '.$sViewboxSmall;
+ $aTerms[] = 'centroid && '.$sViewboxSmall;
}
if ($this->oNearPoint) {
/////////// Sort functions
- static function bySearchRank($a, $b)
+
+ public static function bySearchRank($a, $b)
{
if ($a->iSearchRank == $b->iSearchRank) {
return $a->iOperator + strlen($a->sHouseNumber)
return $a->iSearchRank < $b->iSearchRank ? -1 : 1;
}
-};
+ //////////// Debugging functions
+
+
+ public function dumpAsHtmlTableRow(&$aWordIDs)
+ {
+ $kf = function ($k) use (&$aWordIDs) {
+ return $aWordIDs[$k];
+ };
+
+ echo "<tr>";
+ echo "<td>$this->iSearchRank</td>";
+ echo "<td>".join(', ', array_map($kf, $this->aName))."</td>";
+ echo "<td>".join(', ', array_map($kf, $this->aNameNonSearch))."</td>";
+ echo "<td>".join(', ', array_map($kf, $this->aAddress))."</td>";
+ echo "<td>".join(', ', array_map($kf, $this->aAddressNonSearch))."</td>";
+ echo "<td>".$this->sCountryCode."</td>";
+ echo "<td>".Operator::toString($this->iOperator)."</td>";
+ echo "<td>".$this->sClass."</td>";
+ echo "<td>".$this->sType."</td>";
+ echo "<td>".$this->sPostcode."</td>";
+ echo "<td>".$this->sHouseNumber."</td>";
+
+ if ($this->oNearPoint) {
+ echo "<td>".$this->oNearPoint->lat()."</td>";
+ echo "<td>".$this->oNearPoint->lon()."</td>";
+ echo "<td>".$this->oNearPoint->radius()."</td>";
+ } else {
+ echo "<td></td><td></td><td></td>";
+ }
+
+ echo "</tr>";
+ }
+}