简体   繁体   English

如何在Symfony2数据库查询中使用MATCH

[英]How To Use MATCH In Symfony2 Database Query

I'm building a search feature for my Symfony2 project, and I wrote the SQL for it as follows: 我正在为我的Symfony2项目构建一个搜索功能,我为它编写了SQL,如下所示:

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' [语法错误]第0行,第96行:错误:预期的已知函数,得到'MATCH'

Is there an alternative I could use instead of MATCH ? 有没有替代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. 目前(正好我可以进行基本测试)我正在使用LIKE,但如果使用多个单词进行搜索,则效果不佳。

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();

Doctrine doesn't support that out-of-the-box, true. Doctrine不支持开箱即用的,真实的。 But you can: 但是你可以:

This is not currently possible with Doctrine2 ORM. Doctrine2 ORM目前无法实现这一目标。 As Doctrine supports many different database vendors and most of them don't have a FULLTEXT search feature, it's not supported at all. 由于Doctrine支持许多不同的数据库供应商,并且大多数供应商没有FULLTEXT搜索功能,因此根本不受支持。

You can always use Doctrine2 DBAL for searching. 您始终可以使用Doctrine2 DBAL进行搜索。 You lose all these nifty orm features, but in my practice they aren't that needed in searching situations anyway. 你失去了所有这些漂亮的orm功能,但在我的实践中,它们并不是搜索情况所需要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM