Add match against support for dql #89
This commit is contained in:
parent
315a369a3b
commit
836c026402
3 changed files with 52 additions and 1 deletions
|
|
@ -38,6 +38,8 @@ doctrine:
|
|||
stcollect: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCollect
|
||||
stsnaptogrid: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STSnapToGrid
|
||||
stoverlaps: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STOverlaps
|
||||
# for match against
|
||||
match_against: App\Doctrine\MatchAgainst
|
||||
numeric_functions:
|
||||
# for postgresql
|
||||
starea: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STArea
|
||||
|
|
|
|||
49
src/Doctrine/MatchAgainst.php
Normal file
49
src/Doctrine/MatchAgainst.php
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace App\Doctrine;
|
||||
|
||||
use Doctrine\ORM\Query\Lexer;
|
||||
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
|
||||
|
||||
/**
|
||||
* "MATCH_AGAINST" "(" {StateFieldPathExpression ","}* InParameter {Literal}? ")"
|
||||
*/
|
||||
class MatchAgainst extends FunctionNode {
|
||||
|
||||
public $columns = array();
|
||||
public $needle;
|
||||
public $mode;
|
||||
|
||||
public function parse(\Doctrine\ORM\Query\Parser $parser) {
|
||||
$parser->match(Lexer::T_IDENTIFIER);
|
||||
$parser->match(Lexer::T_OPEN_PARENTHESIS);
|
||||
do {
|
||||
$this->columns[] = $parser->StateFieldPathExpression();
|
||||
$parser->match(Lexer::T_COMMA);
|
||||
} while ($parser->getLexer()->isNextToken(Lexer::T_IDENTIFIER));
|
||||
$this->needle = $parser->InParameter();
|
||||
while ($parser->getLexer()->isNextToken(Lexer::T_STRING)) {
|
||||
$this->mode = $parser->Literal();
|
||||
}
|
||||
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
|
||||
}
|
||||
|
||||
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) {
|
||||
$haystack = null;
|
||||
$first = true;
|
||||
foreach ($this->columns as $column) {
|
||||
$first ? $first = false : $haystack .= ', ';
|
||||
$haystack .= $column->dispatch($sqlWalker);
|
||||
}
|
||||
$query = "MATCH(" . $haystack .
|
||||
") AGAINST (" . $this->needle->dispatch($sqlWalker);
|
||||
if ($this->mode) {
|
||||
$query .= " " . $this->mode->dispatch($sqlWalker) . " )";
|
||||
} else {
|
||||
$query .= " )";
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ use DateTime;
|
|||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="customer_vehicle")
|
||||
* @ORM\Table(name="customer_vehicle", indexes={@ORM\Index(columns={"plate_number"}, flags={"fulltext"})})
|
||||
*/
|
||||
class CustomerVehicle
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue