Skip to content

Basic Phoenix project to validate an Ecto issue regarding MySQL's fulltext search

Notifications You must be signed in to change notification settings

bigardone/ecto_mysql_fulltext_issue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FulltextIssue

Installation

  • Install dependencies with mix deps.get
  • Create and migrate your database with mix ecto.setup
  • Install Node.js dependencies with cd assets && npm install
  • Start Phoenix endpoint with mix phx.server

The issue

Using Ecto fragments with MySQL fulltext search does not work properly on tests using Ecto.Adapters.SQL.Sandbox, although it works correctly in any other env.

The second migration file adds a fulltext index to the users table against its email, first_name and last_name columns.

defmodule FulltextIssue.Repo.Migrations.AddFulltextIndexToUsers do
  use Ecto.Migration

  def change do
    execute("ALTER TABLE users add FULLTEXT (email,first_name,last_name);")
  end
end

The User module has a function which runs the fulltext search:

  def fulltext_search(query \\ User, text) do
    query =
      from(d in query,
        where:
          fragment(
            "MATCH (email,first_name,last_name) AGAINST (? IN NATURAL LANGUAGE MODE)",
            ^text
          )
      )

    Repo.all(query)
  end

If we run the interactive shell and call the function, everything goes as expected:

iex

However, running the test for the user module fails:

iex

About

Basic Phoenix project to validate an Ecto issue regarding MySQL's fulltext search

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published