View Source Ecto MySQL Match

CI codecov Module Version Hex Docs Total Download License Last Updated

Use MySQL match to enable fulltext search on one or more columns.

todo

Todo

  • [ ] Support WITH QUERY EXPANSION
  • [ ] Support IN BOOLEAN MODE
  • [ ] Improve docs (examples) and tests

installation

Installation

The package can be installed by adding :ecto_mysql_match to your list of dependencies in mix.exs:

def deps do
  [
    {:ecto_mysql_match, "~> 0.1.0"}
  ]
end

usage

Usage

To enable fulltext search you must first add the FULLTEXT index on one our more columns.

To add during table creation:

CREATE TABLE posts(
        id INT AUTO_INCREMENT PRIMARY KEY,
        title VARCHAR(255),
        description VARCHAR(255),
        FULLTEXT(title),
        FULLTEXT(title, description))

To add on existing table:

ALTER TABLE posts
        ADD FULLTEXT(title),
        ADD FULLTEXT(title, description)

Depending on your use case you probably want to add the index on separate columns or on a combination of them. Keep in mind that you need to provide the full list of columns when you add the index to multiple columns.

Once the index has been created you can use it in an Ecto query:

import Ecto.Query
import EctoMySQLMatch

from(p in "posts", where: match(p.title, "another"), select: p.title)

from(p in "posts", where: match([p.title, p.description], "another"), select: p.title)

resources

Resources