Reputation: 6625
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
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