mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 20:37:59 +01:00
18 lines
441 B
Elixir
18 lines
441 B
Elixir
defmodule Philomena.Schema.Search do
|
|
alias Philomena.Images.Query
|
|
alias Philomena.Search.String
|
|
import Ecto.Changeset
|
|
|
|
def validate_search(changeset, field, user, watched \\ false) do
|
|
query = changeset |> get_field(field) |> String.normalize()
|
|
output = Query.compile(user, query, watched)
|
|
|
|
case output do
|
|
{:ok, _} ->
|
|
changeset
|
|
|
|
_ ->
|
|
add_error(changeset, field, "is invalid")
|
|
end
|
|
end
|
|
end
|