Michael St Clair
Michael St Clair

Reputation: 6625

Ecto not allowing fragment parameter for mysql fulltext search

I am trying to implement fulltext search in ecto with a fragment. However, it is throwing an error that it won't allow me to use the parameter for search term.

parameters must be of length 1 for query %Mariaex.Query

ZB.Repo.all(
  from contact in ZB.Contact,
  where: contact.account_id == ^account_id,
  where: fragment("MATCH (name,email,phone,address_1,city,state,postal_code) AGAINST ('?*' IN BOOLEAN MODE)", ^search_term)
)

Upvotes: 2

Views: 441

Answers (1)

Dogbert
Dogbert

Reputation: 222348

? in fragment is not plain string substitution. You need to append the * outside the fragment SQL, and the fragment SQL should have just (? IN BOOLEAN MODE).

Change:

fragment("... AGAINST ('?*' IN BOOLEAN MODE)", ^search_term)

To:

fragment("... AGAINST (? IN BOOLEAN MODE)", ^(search_term <> "*"))

Upvotes: 4

Related Questions