diff --git a/lib/philomena_web/plugs/image_filter_plug.ex b/lib/philomena_web/plugs/image_filter_plug.ex index 51534e30..37e33032 100644 --- a/lib/philomena_web/plugs/image_filter_plug.ex +++ b/lib/philomena_web/plugs/image_filter_plug.ex @@ -14,8 +14,8 @@ defmodule PhilomenaWeb.ImageFilterPlug do filter = conn.assigns[:current_filter] tag_exclusion = %{terms: %{tag_ids: filter.hidden_tag_ids}} - {:ok, query_exclusion} = Query.compile(user, normalize(filter.hidden_complex_str)) - {:ok, query_spoiler} = Query.compile(user, normalize(filter.spoilered_complex_str)) + query_exclusion = invalid_filter_guard(user, filter.hidden_complex_str) + query_spoiler = invalid_filter_guard(user, filter.spoilered_complex_str) query = %{ bool: %{ @@ -28,4 +28,11 @@ defmodule PhilomenaWeb.ImageFilterPlug do |> assign(:compiled_complex_spoiler, query_spoiler) |> assign(:compiled_filter, query) end + + defp invalid_filter_guard(user, search_string) do + case Query.compile(user, normalize(search_string)) do + {:ok, query} -> query + _error -> %{match_all: %{}} + end + end end