title: Symfony 3 : fulltext search
body: <p>For my full text searchI used <a href="https://gist.github.com/ZeBigDuck/1234419/edaa13a851b1ea1e9926ec9c003ad762876ffe1d" rel="nofollow noreferrer">https://gist.github.com/ZeBigDuck/1234419/edaa13a851b1ea1e9926ec9c003ad762876ffe1d</a></p>
  
  <p>It returns me an array with a score,:</p>
  
  <pre><code>array:1 [▼
  0 =&gt; array:1 [▼
  "score" =&gt; "2.181887149810791"
   ]
  ]
  </code></pre>
  
  <p>but I want it to return a collection of entity. How?</p>
  
  <p>MatchAgainst class :</p>
  
  <p>`<br>
      
  
  <pre><code>use Doctrine\ORM\Query\Lexer;
  use Doctrine\ORM\Query\AST\Functions\FunctionNode;
  
  class MatchAgainst extends FunctionNode
  {    
  public $columns = array();
  public $needle;
  
  public function parse(\Doctrine\ORM\Query\Parser $parser)
  {
      $parser-&gt;match(Lexer::T_IDENTIFIER);
      $parser-&gt;match(Lexer::T_OPEN_PARENTHESIS);
  
      do {
          $this-&gt;columns[] = $parser-&gt;StateFieldPathExpression();
          $parser-&gt;match(Lexer::T_COMMA);
      } while (!$parser-&gt;getLexer()-&gt;isNextToken(Lexer::T_INPUT_PARAMETER));
  
      // Got an input parameter
      $this-&gt;needle = $parser-&gt;InputParameter();
  
      $parser-&gt;match(Lexer::T_CLOSE_PARENTHESIS);
  }
  
  public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
  {
      $haystack = null;
  
      $first = true;
      foreach ($this-&gt;columns as $column) {
          $first ? $first = false : $haystack .= ', ';
          $haystack .= $column-&gt;dispatch($sqlWalker);
      }
  
      return "MATCH(" .
          $haystack .
          ") AGAINST (" .
          $this-&gt;needle-&gt;dispatch($sqlWalker) .
          " IN BOOLEAN MODE )";
  }
  }
  </code></pre>
  
  <p>`</p>
  
  <p>in my repository :</p>
  
  <pre><code>    $query = $this-&gt;getEntityManager()-&gt;createQuery('
          SELECT
          MATCH_AGAINST (d.title, :searchTerms) as score
          FROM AppBundle:Doc d
          WHERE MATCH_AGAINST (d.title, :searchTerms) &gt; 1
          ORDER BY score desc
      ')
      -&gt;setParameter('searchTerms', $q)
      ;
  </code></pre>
  
  <p>If i change my repository function to smething like</p>
  
  <pre><code>    $query = $this-&gt;getEntityManager()-&gt;createQuery('
          SELECT d
          FROM AppBundle:Doc d
          MATCH_AGAINST (d.title, :searchTerms)        
      ')
      -&gt;setParameter('searchTerms', $q)
      ;
  </code></pre>
  
  <p>I got </p>
  
  <blockquote>
    <p>Error: Expected end of string, got 'MATCH_AGAINST'</p>
  </blockquote>