mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 04:27:59 +01:00
add invalid filter guard to user query compiler
This commit is contained in:
parent
46602460ea
commit
6c3515799b
1 changed files with 9 additions and 14 deletions
|
@ -28,14 +28,8 @@ defmodule Philomena.Images.Query do
|
||||||
|
|
||||||
tag_include = %{terms: %{tag_ids: user.watched_tag_ids}}
|
tag_include = %{terms: %{tag_ids: user.watched_tag_ids}}
|
||||||
|
|
||||||
{:ok, include_query} =
|
include_query = invalid_filter_guard(ctx, user.watched_images_query_str)
|
||||||
Philomena.Images.Query.parse_user(ctx, user.watched_images_query_str |> Search.String.normalize())
|
exclude_query = invalid_filter_guard(ctx, user.watched_images_exclude_str)
|
||||||
|
|
||||||
{:ok, exclude_query} =
|
|
||||||
Philomena.Images.Query.parse_user(
|
|
||||||
ctx,
|
|
||||||
user.watched_images_exclude_str |> Search.String.normalize()
|
|
||||||
)
|
|
||||||
|
|
||||||
should = [tag_include, include_query]
|
should = [tag_include, include_query]
|
||||||
must_not = [exclude_query]
|
must_not = [exclude_query]
|
||||||
|
@ -45,12 +39,7 @@ defmodule Philomena.Images.Query do
|
||||||
user = user |> Repo.preload(:current_filter)
|
user = user |> Repo.preload(:current_filter)
|
||||||
|
|
||||||
tag_exclude = %{terms: %{tag_ids: user.current_filter.spoilered_tag_ids}}
|
tag_exclude = %{terms: %{tag_ids: user.current_filter.spoilered_tag_ids}}
|
||||||
|
spoiler_query = invalid_filter_guard(ctx, user.current_filter.spoilered_complex_str)
|
||||||
{:ok, spoiler_query} =
|
|
||||||
Philomena.Images.Query.parse_user(
|
|
||||||
ctx,
|
|
||||||
user.current_filter.spoilered_complex_str |> Search.String.normalize()
|
|
||||||
)
|
|
||||||
|
|
||||||
[tag_exclude, spoiler_query | must_not]
|
[tag_exclude, spoiler_query | must_not]
|
||||||
else
|
else
|
||||||
|
@ -63,6 +52,12 @@ defmodule Philomena.Images.Query do
|
||||||
def user_my_transform(_ctx, _value),
|
def user_my_transform(_ctx, _value),
|
||||||
do: {:error, "Unknown `my' value."}
|
do: {:error, "Unknown `my' value."}
|
||||||
|
|
||||||
|
defp invalid_filter_guard(ctx, search_string) do
|
||||||
|
case Philomena.Images.Query.parse_user(ctx, Search.String.normalize(search_string)) do
|
||||||
|
{:ok, query} -> query
|
||||||
|
_error -> %{match_all: %{}}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
int_fields = ~W(id width height comment_count score upvotes downvotes faves uploader_id faved_by_id tag_count)
|
int_fields = ~W(id width height comment_count score upvotes downvotes faves uploader_id faved_by_id tag_count)
|
||||||
float_fields = ~W(aspect_ratio wilson_score)
|
float_fields = ~W(aspect_ratio wilson_score)
|
||||||
|
|
Loading…
Reference in a new issue