I’m building a search feature for my Symfony2 project, and I wrote the SQL for it as follows:
SELECT dlc.title, dlc.description, dlc.keywords
FROM ShoutMainBundle:Dlc dlc
WHERE MATCH (dlc.title, dlc.description, dlc.keywords) AGAINST (":keyword" IN BOOLEAN MODE)
AND dlc.type = (":audio")
ORDER BY dlc.date DESC
However, when I run this in the project the following error is given:
[Syntax Error] line 0, col 96: Error: Expected known function, got
‘MATCH’
Is there an alternative I could use instead of MATCH? At the moment (just so I can do basic testing) I’m using LIKE, but it doesn’t work too well if it’s more than one word being used to search with.
EDIT:
This is how the code is used within the code:
$em = $this->getDoctrine()->getEntityManager();
$wckeyword = '%'.$skeyword.'%';
$dlcresult = $em->createQuery('
SELECT dlc.title, dlc.description, dlc.keywords
FROM ShoutMainBundle:Dlc dlc
WHERE MATCH (dlc.title, dlc.description, dlc.keywords) AGAINST (":keyword" IN BOOLEAN MODE)
AND dlc.type = (":audio")
ORDER BY dlc.date DESC'
)->setParameters(array('type' => $stype, 'keyword' => $wckeyword));
$dlcres = $dlcresult->getResult();
This is not currently possible with Doctrine2 ORM. As Doctrine supports many different database vendors and most of them don’t have a
FULLTEXTsearch feature, it’s not supported at all.You can always use Doctrine2 DBAL for searching. You lose all these nifty orm features, but in my practice they aren’t that needed in searching situations anyway.