I am desperatelly trying to include the LEVENSHTEIN function in Symfony2, however, I still receive errors. Specs + what I've done so far:
- PostgreSQL 9.3
- LEVENSHTEIN included in fuzzystrmatch extension
Tested the function via shell execution. Works perfectly fine:
postgres=# SELECT levenshtein('test', 'text'); levenshtein ------------- 1 (1 row)Added the function in DQL:
<?php namespace AppBundle\DQL; use Doctrine\ORM\Query\AST\Functions\FunctionNode; use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; class LevenshteinFunction extends FunctionNode { public $firstStringExpression = null; public $secondStringExpression = null; public function getSql(SqlWalker $sqlWalker) { return 'LEVENSHTEIN(' . $this->firstStringExpression->dispatch($sqlWalker) . ', ' . $this->secondStringExpression->dispatch($sqlWalker) . ')'; } public function parse(Parser $parser) { // levenshtein(str1, str2) $parser->match(Lexer::T_IDENTIFIER); $parser->match(Lexer::T_OPEN_PARENTHESIS); $this->firstStringExpression = $parser->StringPrimary(); $parser->match(Lexer::T_COMMA); $this->secondStringExpression = $parser->StringPrimary(); $parser->match(Lexer::T_CLOSE_PARENTHESIS); } }Config.yml
orm: auto_generate_proxy_classes: "%kernel.debug%" auto_mapping: true dql: numeric_functions: LEVENSHTEIN: AppBundle\DQL\LevenshteinFunctionProblem: When executing the following codeblock in my Repository, the following errors occur:
$this->getEntityManager()->createQuery("SELECT LEVENSHTEIN('test', 'text') FROM AppBundle:User"); return $query->getResult();SQLSTATE[42883]: Undefined function: 7 ERROR: function levenshtein(unknown, unknown) does not exist
What am I missing? Why isn't DQL/Symfony/PDO/... recognizing the function? Any help is highly appreciated!