mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
flesh out my:watched
This commit is contained in:
parent
287556cca7
commit
4b52640efc
2 changed files with 87 additions and 6 deletions
|
@ -1,5 +1,7 @@
|
||||||
defmodule Philomena.Images.Query do
|
defmodule Philomena.Images.Query do
|
||||||
import Philomena.Search.Parser
|
import Philomena.Search.Parser
|
||||||
|
import Philomena.Search.String
|
||||||
|
alias Philomena.Repo
|
||||||
|
|
||||||
defparser("anonymous",
|
defparser("anonymous",
|
||||||
int:
|
int:
|
||||||
|
@ -43,9 +45,44 @@ defmodule Philomena.Images.Query do
|
||||||
%{user: %{id: id}}, "downvotes" ->
|
%{user: %{id: id}}, "downvotes" ->
|
||||||
%{term: %{downvoter_ids: id}}
|
%{term: %{downvoter_ids: id}}
|
||||||
|
|
||||||
%{user: _u}, "watched" ->
|
%{watch: true}, "watched" ->
|
||||||
# todo
|
raise ArgumentError, "Recursive watchlists are not allowed."
|
||||||
%{query: %{match_all: %{}}}
|
|
||||||
|
%{user: user} = ctx, "watched" ->
|
||||||
|
ctx = Map.merge(ctx, %{watch: true})
|
||||||
|
|
||||||
|
tag_include = %{terms: %{tag_ids: user.watched_tag_ids}}
|
||||||
|
|
||||||
|
{:ok, include_query} =
|
||||||
|
Philomena.Images.Query.user_parser(ctx, user.watched_images_query |> normalize())
|
||||||
|
|
||||||
|
{:ok, exclude_query} =
|
||||||
|
Philomena.Images.Query.user_parser(
|
||||||
|
ctx,
|
||||||
|
user.watched_images_exclude_query |> normalize()
|
||||||
|
)
|
||||||
|
|
||||||
|
should = [tag_include, include_query]
|
||||||
|
must_not = [exclude_query]
|
||||||
|
|
||||||
|
must_not =
|
||||||
|
if user.no_spoilered_in_watched do
|
||||||
|
user = user |> Repo.preload(:current_filter)
|
||||||
|
|
||||||
|
tag_exclude = %{terms: %{tag_ids: user.current_filter.spoilered_tag_ids}}
|
||||||
|
|
||||||
|
{:ok, spoiler_query} =
|
||||||
|
Philomena.Images.Query.user_parser(
|
||||||
|
ctx,
|
||||||
|
user.current_filter.spoilered_complex_str |> normalize()
|
||||||
|
)
|
||||||
|
|
||||||
|
[tag_exclude, spoiler_query | must_not]
|
||||||
|
else
|
||||||
|
must_not
|
||||||
|
end
|
||||||
|
|
||||||
|
%{bool: %{should: should, must_not: must_not}}
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
aliases: %{
|
aliases: %{
|
||||||
|
@ -80,9 +117,44 @@ defmodule Philomena.Images.Query do
|
||||||
%{user: %{id: id}}, "downvotes" ->
|
%{user: %{id: id}}, "downvotes" ->
|
||||||
%{term: %{downvoter_ids: id}}
|
%{term: %{downvoter_ids: id}}
|
||||||
|
|
||||||
%{user: _u}, "watched" ->
|
%{watch: true}, "watched" ->
|
||||||
# todo
|
raise ArgumentError, "Recursive watchlists are not allowed."
|
||||||
%{query: %{match_all: %{}}}
|
|
||||||
|
%{user: user} = ctx, "watched" ->
|
||||||
|
ctx = Map.merge(ctx, %{watch: true})
|
||||||
|
|
||||||
|
tag_include = %{terms: %{tag_ids: user.watched_tag_ids}}
|
||||||
|
|
||||||
|
{:ok, include_query} =
|
||||||
|
Philomena.Images.Query.moderator_parser(ctx, user.watched_images_query |> normalize())
|
||||||
|
|
||||||
|
{:ok, exclude_query} =
|
||||||
|
Philomena.Images.Query.moderator_parser(
|
||||||
|
ctx,
|
||||||
|
user.watched_images_exclude_query |> normalize()
|
||||||
|
)
|
||||||
|
|
||||||
|
should = [tag_include, include_query]
|
||||||
|
must_not = [exclude_query]
|
||||||
|
|
||||||
|
must_not =
|
||||||
|
if user.no_spoilered_in_watched do
|
||||||
|
user = user |> Repo.preload(:current_filter)
|
||||||
|
|
||||||
|
tag_exclude = %{terms: %{tag_ids: user.current_filter.spoilered_tag_ids}}
|
||||||
|
|
||||||
|
{:ok, spoiler_query} =
|
||||||
|
Philomena.Images.Query.moderator_parser(
|
||||||
|
ctx,
|
||||||
|
user.current_filter.spoilered_complex_str |> normalize()
|
||||||
|
)
|
||||||
|
|
||||||
|
[tag_exclude, spoiler_query | must_not]
|
||||||
|
else
|
||||||
|
must_not
|
||||||
|
end
|
||||||
|
|
||||||
|
%{bool: %{should: should, must_not: must_not}}
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
aliases: %{
|
aliases: %{
|
||||||
|
|
9
lib/philomena/search/string.ex
Normal file
9
lib/philomena/search/string.ex
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
defmodule Philomena.Search.String do
|
||||||
|
def normalize(str) do
|
||||||
|
str
|
||||||
|
|> String.replace("\r", "")
|
||||||
|
|> String.split("\n")
|
||||||
|
|> Enum.map(fn s -> "(#{s})" end)
|
||||||
|
|> Enum.join(" || ")
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue