$aSearches = array_merge($aSearches, $aNewSearches);
if ($iSearchCount > 50) break;
}
-
- //if (CONST_Debug) _debugDumpGroupedSearches($aGroupedSearches, $aValidTokens);
}
// Revisit searches, drop bad searches and give penalty to unlikely combinations.
public function lookup()
{
+ Debug::newFunction('Geocode::lookup');
if (!$this->sQuery && !$this->aStructuredQuery) return array();
+ Debug::printDebugArray('Geocode', $this);
+
$oCtx = new SearchContext();
if ($this->aRoutePoints) {
$oCtx->setCountryList($this->aCountryCodes);
}
+ Debug::newSection('Query Preprocessing');
+
$sNormQuery = $this->normTerm($this->sQuery);
+ Debug::printVar('Normalized query', $sNormQuery);
+
$sLanguagePrefArraySQL = getArraySQL(
array_map('getDBQuoted', $this->aLangPrefOrder)
);
$aSpecialTermsRaw,
PREG_SET_ORDER
);
+ if (!empty($aSpecialTermsRaw)) {
+ Debug::printVar('Special terms', $aSpecialTermsRaw);
+ }
+
foreach ($aSpecialTermsRaw as $aSpecialTerm) {
$sQuery = str_replace($aSpecialTerm[0], ' ', $sQuery);
if (!$sSpecialTerm) {
$sSQL = 'SELECT class, type FROM word ';
$sSQL .= ' WHERE word_token in (\' '.$sToken.'\')';
$sSQL .= ' AND class is not null AND class not in (\'place\')';
- if (CONST_Debug) var_Dump($sSQL);
+
+ Debug::printSQL($sSQL);
$aSearchWords = chksql($this->oDB->getAll($sSQL));
$aNewSearches = array();
foreach ($aSearches as $oSearch) {
$bStructuredPhrases = false;
}
+ Debug::printDebugArray('Search context', $oCtx);
+ Debug::printDebugArray('Base search', empty($aSearches) ? null : $aSearches[0]);
+ Debug::printVar('Final query phrases', $aInPhrases);
+
// Convert each phrase to standard form
// Create a list of standard words
// Get all 'sets' of words
// Generate a complete list of all
+ Debug::newSection('Tokenization');
$aTokens = array();
$aPhrases = array();
foreach ($aInPhrases as $iPhrase => $sPhrase) {
}
}
+ Debug::printDebugTable('Phrases', $aPhrases);
+ Debug::printVar('Tokens', $aTokens);
+
if (!empty($aTokens)) {
// Check which tokens we have, get the ID numbers
$sSQL = 'SELECT word_id, word_token, word, class, type, country_code, operator, search_name_count';
$sSQL .= ' FROM word ';
$sSQL .= ' WHERE word_token in ('.join(',', array_map('getDBQuoted', $aTokens)).')';
- if (CONST_Debug) var_Dump($sSQL);
+ Debug::printSQL($sSQL);
$aValidTokens = array();
$aDatabaseWords = chksql(
$this->oDB->getAll($sSQL),
'Could not get word tokens.'
);
- $aWordFrequencyScores = array();
foreach ($aDatabaseWords as $aToken) {
// Filter country tokens that do not match restricted countries.
if ($this->aCountryCodes
} else {
$aValidTokens[$aToken['word_token']] = array($aToken);
}
- $aWordFrequencyScores[$aToken['word_id']] = $aToken['search_name_count'] + 1;
}
- if (CONST_Debug) var_Dump($aPhrases, $aValidTokens);
// US ZIP+4 codes - if there is no token, merge in the 5-digit ZIP code
foreach ($aTokens as $sToken) {
$aValidTokens[' '.$sToken] = array(array('class' => 'place', 'type' => 'house', 'word_token' => ' '.$sToken));
}
}
+ Debug::printGroupTable('Valid Tokens', $aValidTokens);
// Any words that have failed completely?
// TODO: suggestions
+ Debug::newSection('Search candidates');
$aGroupedSearches = $this->getGroupedSearches($aSearches, $aPhrases, $aValidTokens, $bStructuredPhrases);
$aResults += $oSearch->query(
$this->oDB,
- $aWordFrequencyScores,
$this->iMinAddressRank,
$this->iMaxAddressRank,
$this->iLimit
$aFilteredIDs = array();
if ($aFilterSql) {
$sSQL = join(' UNION ', $aFilterSql);
- if (CONST_Debug) var_dump($sSQL);
+ Debug::printSQL($sSQL);
$aFilteredIDs = chksql($this->oDB->getCol($sSQL));
}
$oLookup = $oReverse->lookupPoint($oCtx->sqlNear, false);
- if (CONST_Debug) var_dump('Reverse search', $aLookup);
+ Debug::printVar('Reverse search', $oLookup);
if ($oLookup) {
$aResults = array($oLookup->iId => $oLookup);
if (!preg_match('/[\pL\pN]/', $sWord)) unset($aRecheckWords[$i]);
}
- if (CONST_Debug) {
- echo '<i>Recheck words:<\i>';
- var_dump($aRecheckWords);
- }
+ Debug::printVar('Recheck words', $aRecheckWords);
foreach ($aSearchResults as $iIdx => $aResult) {
// Default
$aResult['foundorder'] += 0.01;
}
}
- if (CONST_Debug) var_dump($aResult);
$aSearchResults[$iIdx] = $aResult;
}
uasort($aSearchResults, 'byImportance');
+ Debug::printVar('Pre-filter results', $aSearchResults);
$aOSMIDDone = array();
$aClassTypeNameDone = array();
$aToFilter = $aSearchResults;
$aSearchResults = array();
- if (CONST_Debug) var_dump($aToFilter);
-
$bFirst = true;
foreach ($aToFilter as $aResult) {
$this->aExcludePlaceIDs[$aResult['place_id']] = $aResult['place_id'];
if (count($aSearchResults) >= $this->iFinalLimit) break;
}
- if (CONST_Debug) var_dump($aSearchResults);
+ Debug::printVar('Post-filter results', $aSearchResults);
return $aSearchResults;
} // end lookup()
+
+ public function debugInfo()
+ {
+ return array(
+ 'Query' => $this->sQuery,
+ 'Structured query' => $this->aStructuredQuery,
+ 'Name keys' => Debug::fmtArrayVals($this->aLangPrefOrder),
+ 'Include address' => $this->bIncludeAddressDetails,
+ 'Excluded place IDs' => Debug::fmtArrayVals($this->aExcludePlaceIDs),
+ 'Try reversed query'=> $this->bReverseInPlan,
+ 'Limit (for searches)' => $this->iLimit,
+ 'Limit (for results)'=> $this->iFinalLimit,
+ 'Country codes' => Debug::fmtArrayVals($this->aCountryCodes),
+ 'Bounded search' => $this->bBoundedSearch,
+ 'Viewbox' => Debug::fmtArrayVals($this->aViewBox),
+ 'Route points' => Debug::fmtArrayVals($this->aRoutePoints),
+ 'Route width' => $this->aRouteWidth,
+ 'Max rank' => $this->iMaxRank,
+ 'Min address rank' => $this->iMinAddressRank,
+ 'Max address rank' => $this->iMaxAddressRank,
+ 'Address rank list' => Debug::fmtArrayVals($this->aAddressRankList)
+ );
+ }
} // end class