mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-20 06:37:59 +01:00
trim terms, add my:hidden
This commit is contained in:
parent
58a045ed29
commit
69c03f483d
7 changed files with 30 additions and 6 deletions
|
@ -17,6 +17,9 @@ defmodule Philomena.Images.Query do
|
|||
def user_my_transform(%{user: %{id: id}}, "uploads"),
|
||||
do: {:ok, %{term: %{true_uploader_id: id}}}
|
||||
|
||||
def user_my_transform(%{user: %{id: id}}, "hidden"),
|
||||
do: {:ok, %{term: %{hidden_by_user_ids: id}}}
|
||||
|
||||
def user_my_transform(%{watch: true}, "watched"),
|
||||
do: {:error, "Recursive watchlists are not allowed."}
|
||||
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
defmodule Search.BoolParser do
|
||||
import NimbleParsec
|
||||
|
||||
space =
|
||||
choice([string(" "), string("\t"), string("\n"), string("\r"), string("\v"), string("\f")])
|
||||
|> ignore()
|
||||
|
||||
bool =
|
||||
choice([
|
||||
string("true"),
|
||||
string("false")
|
||||
])
|
||||
|> repeat(space)
|
||||
|> unwrap_and_tag(:bool)
|
||||
|> eos()
|
||||
|> label("a boolean, like `true' or `false'")
|
||||
|
|
|
@ -181,6 +181,7 @@ defmodule Search.DateParser do
|
|||
absolute_date,
|
||||
relative_date
|
||||
])
|
||||
|> repeat(space)
|
||||
|> eos()
|
||||
|> label("a RFC3339 datetime fragment, like `2019-01-01', or relative date, like `3 days ago'")
|
||||
|
||||
|
|
|
@ -2,6 +2,10 @@ defmodule Search.FloatParser do
|
|||
import NimbleParsec
|
||||
import Search.Helpers
|
||||
|
||||
space =
|
||||
choice([string(" "), string("\t"), string("\n"), string("\r"), string("\v"), string("\f")])
|
||||
|> ignore()
|
||||
|
||||
fuzz =
|
||||
string("~")
|
||||
|> ignore()
|
||||
|
@ -24,6 +28,7 @@ defmodule Search.FloatParser do
|
|||
float |> concat(fuzz) |> concat(unsigned_float) |> reduce(:range) |> unwrap_and_tag(:float_range),
|
||||
float |> unwrap_and_tag(:float)
|
||||
])
|
||||
|> repeat(space)
|
||||
|> eos()
|
||||
|> label("a real number, like `2.7182818' or `-10'")
|
||||
|
||||
|
|
|
@ -2,6 +2,10 @@ defmodule Search.IntParser do
|
|||
import NimbleParsec
|
||||
import Search.Helpers
|
||||
|
||||
space =
|
||||
choice([string(" "), string("\t"), string("\n"), string("\r"), string("\v"), string("\f")])
|
||||
|> ignore()
|
||||
|
||||
fuzz =
|
||||
string("~")
|
||||
|> ignore()
|
||||
|
@ -17,6 +21,7 @@ defmodule Search.IntParser do
|
|||
int |> concat(fuzz) |> integer(min: 1) |> reduce(:range) |> unwrap_and_tag(:int_range),
|
||||
int |> unwrap_and_tag(:int)
|
||||
])
|
||||
|> repeat(space)
|
||||
|> eos()
|
||||
|> label("an integer, like `3' or `-10'")
|
||||
|
||||
|
|
|
@ -124,12 +124,17 @@ defmodule Search.IpParser do
|
|||
])
|
||||
|> reduce({List, :to_string, []})
|
||||
|
||||
space =
|
||||
choice([string(" "), string("\t"), string("\n"), string("\r"), string("\v"), string("\f")])
|
||||
|> ignore()
|
||||
|
||||
ip =
|
||||
choice([
|
||||
ipv4_address |> optional(ipv4_prefix),
|
||||
ipv6_address |> optional(ipv6_prefix)
|
||||
])
|
||||
|> reduce({Enum, :join, []})
|
||||
|> repeat(space)
|
||||
|> unwrap_and_tag(:ip)
|
||||
|> eos()
|
||||
|> label("a valid IPv4 or IPv6 address and optional CIDR prefix")
|
||||
|
|
|
@ -192,29 +192,29 @@ defmodule Search.Parser do
|
|||
# Types which do not support ranges
|
||||
|
||||
defp field_type(parser, [{LiteralParser, field_name}, range: :eq, literal: value]),
|
||||
do: {:ok, {%{term: %{field(parser, field_name) => value}}, []}}
|
||||
do: {:ok, {%{term: %{field(parser, field_name) => String.trim(value)}}, []}}
|
||||
|
||||
defp field_type(parser, [{LiteralParser, field_name}, range: :eq, literal: value, fuzz: fuzz]),
|
||||
do: {:ok, {%{fuzzy: %{field(parser, field_name) => %{value: value, fuzziness: fuzz}}}, []}}
|
||||
do: {:ok, {%{fuzzy: %{field(parser, field_name) => %{value: String.trim(value), fuzziness: fuzz}}}, []}}
|
||||
|
||||
defp field_type(_parser, [{LiteralParser, _field_name}, range: :eq, wildcard: "*"]),
|
||||
do: {:ok, {%{match_all: %{}}, []}}
|
||||
|
||||
defp field_type(parser, [{LiteralParser, field_name}, range: :eq, wildcard: value]),
|
||||
do: {:ok, {%{wildcard: %{field(parser, field_name) => value}}, []}}
|
||||
do: {:ok, {%{wildcard: %{field(parser, field_name) => String.trim(value)}}, []}}
|
||||
|
||||
|
||||
defp field_type(parser, [{NgramParser, field_name}, range: :eq, literal: value]),
|
||||
do: {:ok, {%{match_phrase: %{field(parser, field_name) => value}}, []}}
|
||||
do: {:ok, {%{match_phrase: %{field(parser, field_name) => String.trim(value)}}, []}}
|
||||
|
||||
defp field_type(parser, [{NgramParser, field_name}, range: :eq, literal: value, fuzz: _fuzz]),
|
||||
do: {:ok, {%{match_phrase: %{field(parser, field_name) => value}}, []}}
|
||||
do: {:ok, {%{match_phrase: %{field(parser, field_name) => String.trim(value)}}, []}}
|
||||
|
||||
defp field_type(_parser, [{NgramParser, _field_name}, range: :eq, wildcard: "*"]),
|
||||
do: {:ok, {%{match_all: %{}}, []}}
|
||||
|
||||
defp field_type(parser, [{NgramParser, field_name}, range: :eq, wildcard: value]),
|
||||
do: {:ok, {%{wildcard: %{field(parser, field_name) => value}}, []}}
|
||||
do: {:ok, {%{wildcard: %{field(parser, field_name) => String.trim(value)}}, []}}
|
||||
|
||||
|
||||
defp field_type(parser, [{BoolParser, field_name}, range: :eq, bool: value]),
|
||||
|
|
Loading…
Reference in a new issue