+ /**
+ * Query database for places that match this search.
+ *
+ * @param object $oDB Database connection to use.
+ * @param mixed[] $aWordFrequencyScores Number of times tokens appears
+ * overall in a planet database.
+ * @param mixed[] $aExactMatchCache Saves number of exact matches.
+ * @param integer $iMinRank Minimum address rank to restrict
+ * search to.
+ * @param integer $iMaxRank Maximum address rank to restrict
+ * search to.
+ * @param integer $iLimit Maximum number of results.
+ *
+ * @return mixed[] An array with two fields: IDs contains the list of
+ * matching place IDs and houseNumber the houseNumber
+ * if appicable or -1 if not.
+ */
+ public function query(&$oDB, &$aWordFrequencyScores, &$aExactMatchCache, $iMinRank, $iMaxRank, $iLimit)
+ {
+ $aPlaceIDs = array();
+ $iHousenumber = -1;
+
+ if ($this->sCountryCode
+ && !sizeof($this->aName)
+ && !$this->iOperator
+ && !$this->sClass
+ && !$this->oContext->hasNearPoint()
+ ) {
+ // Just looking for a country - look it up
+ if (4 >= $iMinRank && 4 <= $iMaxRank) {
+ $aPlaceIDs = $this->queryCountry($oDB);
+ }
+ } elseif (!sizeof($this->aName) && !sizeof($this->aAddress)) {
+ // Neither name nor address? Then we must be
+ // looking for a POI in a geographic area.
+ if ($this->oContext->isBoundedSearch()) {
+ $aPlaceIDs = $this->queryNearbyPoi($oDB, $iLimit);
+ }
+ } elseif ($this->iOperator == Operator::POSTCODE) {
+ // looking for postcode
+ $aPlaceIDs = $this->queryPostcode($oDB, $iLimit);
+ } else {
+ // Ordinary search:
+ // First search for places according to name and address.
+ $aNamedPlaceIDs = $this->queryNamedPlace(
+ $oDB,
+ $aWordFrequencyScores,
+ $iMinRank,
+ $iMaxRank,
+ $iLimit
+ );
+
+ if (sizeof($aNamedPlaceIDs)) {
+ foreach ($aNamedPlaceIDs as $aRow) {
+ $aPlaceIDs[] = $aRow['place_id'];
+ $aExactMatchCache[$aRow['place_id']] = $aRow['exactmatch'];
+ }
+ }
+
+ //now search for housenumber, if housenumber provided
+ if ($this->sHouseNumber && sizeof($aPlaceIDs)) {
+ $aResult = $this->queryHouseNumber($oDB, $aPlaceIDs, $iLimit);
+
+ if (sizeof($aResult)) {
+ $iHousenumber = $aResult['iHouseNumber'];
+ $aPlaceIDs = $aResult['aPlaceIDs'];
+ } elseif (!$this->looksLikeFullAddress()) {
+ $aPlaceIDs = array();
+ }
+ }
+
+ // finally get POIs if requested
+ if ($this->sClass && sizeof($aPlaceIDs)) {
+ $aPlaceIDs = $this->queryPoiByOperator($oDB, $aPlaceIDs, $iLimit);
+ }
+ }
+
+ if (CONST_Debug) {
+ echo "<br><b>Place IDs:</b> ";
+ var_Dump($aPlaceIDs);
+ }
+
+ if (sizeof($aPlaceIDs) && $this->sPostcode) {
+ $sSQL = 'SELECT place_id FROM placex';
+ $sSQL .= ' WHERE place_id in ('.join(',', $aPlaceIDs).')';
+ $sSQL .= " AND postcode = '".$this->sPostcode."'";
+ if (CONST_Debug) var_dump($sSQL);
+ $aFilteredPlaceIDs = chksql($oDB->getCol($sSQL));
+ if ($aFilteredPlaceIDs) {
+ $aPlaceIDs = $aFilteredPlaceIDs;
+ if (CONST_Debug) {
+ echo "<br><b>Place IDs after postcode filtering:</b> ";
+ var_Dump($aPlaceIDs);
+ }
+ }
+ }
+
+ return array('IDs' => $aPlaceIDs, 'houseNumber' => $iHousenumber);
+ }
+
+
+ private function queryCountry(&$oDB)