使用注释在Doctrine 2中添加FULLTEXT索引?

时间:2014-05-03 18:23:42

标签: mysql symfony doctrine-orm full-text-search

我知道Doctrine 2不支持FULLTEXT索引。我实际上使用结果集映射和本地查询到FULLTEXT搜索innodb表(MySQL 5.6)。但是我仍然需要将一个或多个实体字段标记为索引的一部分。

有没有办法使用注释添加索引?似乎@Index注释没有指定...的类型

2 个答案:

答案 0 :(得分:41)

根据Doctrine问题跟踪器中的DDC-3014,使用注释指定全文索引的可能性已于4月14日实施,将在2.5版中提供。如果您不想等待,可以尝试使用不稳定的开发版本或反向移植the commit来实现该功能。

以下是一个用法示例:

/**
* @Entity
* @Table(indexes={@Index(columns={"content"}, flags={"fulltext"})})
*/
class Comment
{
    /**
    * @Column(type="text")
    */
    private $content;

    ...
}

答案 1 :(得分:2)

以下是如何使用yaml映射驱动程序创建全文索引的示例。

Doctrine\Tests\ORM\Mapping\Comment:
    type: entity
    fields:
        content:
            type: text
    indexes:
        xy_fulltext:
            columns: ["name", "content", "keywords"]
            flags: fulltext