Categories
Software Development Web Development

How to add a fulltext index in Doctrine with Symfony 5+

I had to google to find this answer on Stackexchange because I can’t find anything in the docs. Apparently this is something new so you don’t have to jump through the old circus hoops of the past.

Apparently you can add a flags section like this to one of the index definitions of your Entity definition.
flags={“fulltext”}

@ORM\Index(name="hashtag_fulltext", columns={"image_hashtag"}, flags={"fulltext"})})

Now when you do a doctrine diff and then migrate your column will have a full text index. I checked this and it works, but it is apparently not documented, not yet anyways. I am glad this useful feature exists and look forward to learning more in the future.

By the way the @ORM/Index section goes within a table section like this

 @ORM\Table(name="images",
*     indexes={@ORM\Index(name="allowResaleIndex", columns={"allow_resale"}),
*     @ORM\Index(name="collectionId", columns={"collection_id"}),
*      @ORM\Index(name="conentRating", columns={"content_rating"}),
*      @ORM\Index(name="modifyType", columns={"modify_type"}),
*     @ORM\Index(name="is_published", columns={"published_status"}),
*     @ORM\Index(name="languageCode", columns={"language_code_id"}),
*     @ORM\Index(name="ownerId", columns={"owner_user_id"}),
*     @ORM\Index(name="title", columns={"title"}),
*      @ORM\Index(name="useType", columns={"use_type"}),
*     @ORM\Index(name="visibilityIndex", columns={"visibility"})})

It is fairly tricky syntax and sort of hard on the eyes to spot issues.

By Robert jackson

This is my website. I write articles about programming and more. I've been programming 16 years now.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: