public function checkStatus()
{
- $sSQL = "SELECT word_id FROM word limit 1";
+ $sSQL = 'SELECT word_id FROM word WHERE word_id is not null limit 1';
$iWordID = $this->oDB->getOne($sSQL);
if ($iWordID === false) {
- throw new Exception('Query failed', 703);
+ throw new \Exception('Query failed', 703);
}
if (!$iWordID) {
- throw new Exception('No value', 704);
+ throw new \Exception('No value', 704);
}
}
private function addTokensFromDB(&$oValidTokens, $aTokens, $sNormQuery)
{
// Check which tokens we have, get the ID numbers
- $sSQL = 'SELECT word_id, word_token, type,';
- $sSQL .= " info->>'cc' as country, info->>'postcode' as postcode,";
+ $sSQL = 'SELECT word_id, word_token, type, word,';
$sSQL .= " info->>'op' as operator,";
$sSQL .= " info->>'class' as class, info->>'type' as ctype,";
$sSQL .= " info->>'count' as count";
switch ($aWord['type']) {
case 'C': // country name tokens
- if ($aWord['country'] !== null
+ if ($aWord['word'] !== null
&& (!$this->aCountryRestriction
- || in_array($aWord['country'], $this->aCountryRestriction))
+ || in_array($aWord['word'], $this->aCountryRestriction))
) {
- $oValidTokens->addToken($sTok, new Token\Country($iId, $aWord['country']));
+ $oValidTokens->addToken(
+ $sTok,
+ new Token\Country($iId, $aWord['word'])
+ );
}
break;
case 'H': // house number tokens
// Postcodes are not normalized, so they may have content
// that makes SQL injection possible. Reject postcodes
// that would need special escaping.
- if ($aWord['postcode'] !== null
- && pg_escape_string($aWord['postcode']) == $aWord['postcode']
+ if ($aWord['word'] !== null
+ && pg_escape_string($aWord['word']) == $aWord['word']
) {
- $sNormPostcode = $this->normalizeString($aWord['postcode']);
+ $sNormPostcode = $this->normalizeString($aWord['word']);
if (strpos($sNormQuery, $sNormPostcode) !== false) {
- $oValidTokens->addToken($sTok, new Token\Postcode($iId, $aWord['postcode'], null));
+ $oValidTokens->addToken(
+ $sTok,
+ new Token\Postcode($iId, $aWord['word'], null)
+ );
}
}
break;
$iId,
$aWord['class'],
$aWord['ctype'],
- (isset($aWord['op'])) ? Operator::NEAR : Operator::NONE
+ (isset($aWord['operator'])) ? Operator::NEAR : Operator::NONE
));
}
break;