Example #1
0
 /**
  * Get SQL query part
  *
  * @param \Doctrine\ORM\Query\SqlWalker $sqlWalker SQL walker
  *
  * @return string
  */
 public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
 {
     $sql = '';
     $phrase = trim($this->relevanceSearchWords->dispatch($sqlWalker), '\'');
     $words = explode(' ', $phrase);
     $titleFactor = round(20 / count($words), 2);
     $textFactor = round(10 / count($words), 2);
     $sql .= '(';
     $sql .= sprintf(' IF (%s LIKE \'%%%s%%\', 60, 0)', $this->relevanceTitleField->dispatch($sqlWalker), $phrase);
     $sql .= '+';
     $sql .= sprintf(' IF (%s LIKE \'%%%s%%\', 10, 0)', $this->relevanceTextField->dispatch($sqlWalker), $phrase);
     foreach ($words as $word) {
         $sql .= '+';
         $sql .= sprintf(' IF (%s LIKE \'%%%s%%\', %s, 0)', $this->relevanceTitleField->dispatch($sqlWalker), $word, $titleFactor);
         $sql .= '+';
         $sql .= sprintf(' IF (%s LIKE \'%%%s%%\', %s, 0)', $this->relevanceTextField->dispatch($sqlWalker), $word, $textFactor);
     }
     $sql .= ')';
     return $sql;
 }
Example #2
0
 /**
  * Simple Manhattan Distance
  * 69.09 = approximate number of miles per degree of latitude.
  *
  * @param Doctrine\ORM\Query\SqlWalker $sqlWalker
  * @return string
  */
 public function getSql(Doctrine\ORM\Query\SqlWalker $sqlWalker)
 {
     $sql = 'ROUND(ABS(' . $this->fromLatitude->dispatch($sqlWalker) . ' - ' . $this->toLatitude->dispatch($sqlWalker) . ') + ABS(' . $this->fromLongitude->dispatch($sqlWalker) . ' - ' . $this->toLongitude->dispatch($sqlWalker) . ') * 69.09, 3)';
     return $sql;
 }
Example #3
0
 /**
  * @param \Doctrine\ORM\Query\SqlWalker $sqlWalker
  * @return string
  */
 public function getSql(SqlWalker $sqlWalker)
 {
     return $this->firstValue->dispatch($sqlWalker) . ' & ' . $this->secondValue->dispatch($sqlWalker);
     // (7)
 }
Example #4
0
 /**
  * Haversine Formula
  * https://developers.google.com/maps/articles/phpsqlsearch_v3
  *
  * @param Doctrine\ORM\Query\SqlWalker $sqlWalker
  * @return string
  */
 public function getSql(Doctrine\ORM\Query\SqlWalker $sqlWalker)
 {
     $sql = 'ROUND(3959 * ACOS(' . 'COS(RADIANS(' . $this->fromLatitude->dispatch($sqlWalker) . '))' . '* COS(RADIANS(' . $this->toLatitude->dispatch($sqlWalker) . '))' . '* COS(RADIANS(' . $this->toLongitude->dispatch($sqlWalker) . ')' . ' - RADIANS(' . $this->fromLongitude->dispatch($sqlWalker) . '))' . '+ SIN(RADIANS(' . $this->fromLatitude->dispatch($sqlWalker) . '))' . '* SIN(RADIANS(' . $this->toLatitude->dispatch($sqlWalker) . '))' . '), 3)';
     return $sql;
 }