Add a FULLTEXT index in Doctrine 2 using annotations?
Asked Answered
V

3

30

I know that Doctrine 2 doesn't support FULLTEXT indexes. I'm actually using a result set mapping and native queries to FULLTEXT search innodb tables (MySQL 5.6). But I still need to mark one or more entity fields as part of the index.

Is there any way to add the index using annotations? It seems that @Index annotation doesn't specify the type of...

Vaporization answered 3/5, 2014 at 18:23 Comment(0)
V
60

According to DDC-3014 in the issue tracker of Doctrine, the possibility to specify full-text indices using annotations was implemented on April 14 and will be available in release 2.5. If you don't like to wait, you could try to use the unstable, development version or to backport the commit implementing the feature.

Here is a usage example:

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

    ...
}
Vuong answered 31/5, 2014 at 3:31 Comment(1)
Works perfectly with doctrine/orm dev-master, thanks. Unfortunately Doctrine extensions does not work yet with Doctrine 2.5, so I can't use it yet. See this issue (it's about Sylius, but refers to the Tree behaviour with doctrine/orm > 2.4.2): github.com/Sylius/Sylius/issues/1325Vaporization
S
4

Since Doctrine 2.9 using PHP 8 attributes:

<?php
#[ORM\Index(columns: ['name'], name: 'name_idx', flags: ['fulltext'])]
#[ORM\Entity(repositoryClass: ItemRepository::class)]
class Item {
    #[ORM\Column(type: Types::TEXT)]
    private string $name;
}

Source: https://www.doctrine-project.org/projects/doctrine-orm/en/2.16/reference/attributes-reference.html#attrref_index

Shani answered 6/10, 2023 at 17:10 Comment(0)
B
3

Here is an example how to make a fulltext index with the yaml mapping driver.

Doctrine\Tests\ORM\Mapping\Comment:
    type: entity
    fields:
        content:
            type: text
    indexes:
        xy_fulltext:
            columns: ["name", "content", "keywords"]
            flags: fulltext
Belden answered 26/9, 2016 at 14:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.