https://github.com/bigardone/ecto_mysql_fulltext_issue
Basic Phoenix project to validate an Ecto issue regarding MySQL's fulltext search
https://github.com/bigardone/ecto_mysql_fulltext_issue
Last synced: 3 months ago
JSON representation
Basic Phoenix project to validate an Ecto issue regarding MySQL's fulltext search
- Host: GitHub
- URL: https://github.com/bigardone/ecto_mysql_fulltext_issue
- Owner: bigardone
- Created: 2020-01-17T08:00:34.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T05:17:03.000Z (over 2 years ago)
- Last Synced: 2025-02-08T10:25:35.730Z (4 months ago)
- Language: Elixir
- Size: 1.84 MB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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](https://dev.mysql.com/doc/refman/5.7/en/fulltext-natural-language.html) index to the `users` table against its `email`, `first_name` and `last_name` columns.
```elixir
defmodule FulltextIssue.Repo.Migrations.AddFulltextIndexToUsers do
use Ecto.Migrationdef 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:
```elixir
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:

However, running the test for the user module fails:
