trim terms, add my:hidden

This commit is contained in:
byte[] 2019-11-15 13:27:10 -05:00
parent 58a045ed29
commit 69c03f483d
7 changed files with 30 additions and 6 deletions

View file

@ -17,6 +17,9 @@ defmodule Philomena.Images.Query do
def user_my_transform(%{user: %{id: id}}, "uploads"), def user_my_transform(%{user: %{id: id}}, "uploads"),
do: {:ok, %{term: %{true_uploader_id: id}}} 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"), def user_my_transform(%{watch: true}, "watched"),
do: {:error, "Recursive watchlists are not allowed."} do: {:error, "Recursive watchlists are not allowed."}

View file

@ -1,11 +1,16 @@
defmodule Search.BoolParser do defmodule Search.BoolParser do
import NimbleParsec import NimbleParsec
space =
choice([string(" "), string("\t"), string("\n"), string("\r"), string("\v"), string("\f")])
|> ignore()
bool = bool =
choice([ choice([
string("true"), string("true"),
string("false") string("false")
]) ])
|> repeat(space)
|> unwrap_and_tag(:bool) |> unwrap_and_tag(:bool)
|> eos() |> eos()
|> label("a boolean, like `true' or `false'") |> label("a boolean, like `true' or `false'")

View file

@ -181,6 +181,7 @@ defmodule Search.DateParser do
absolute_date, absolute_date,
relative_date relative_date
]) ])
|> repeat(space)
|> eos() |> eos()
|> label("a RFC3339 datetime fragment, like `2019-01-01', or relative date, like `3 days ago'") |> label("a RFC3339 datetime fragment, like `2019-01-01', or relative date, like `3 days ago'")

View file

@ -2,6 +2,10 @@ defmodule Search.FloatParser do
import NimbleParsec import NimbleParsec
import Search.Helpers import Search.Helpers
space =
choice([string(" "), string("\t"), string("\n"), string("\r"), string("\v"), string("\f")])
|> ignore()
fuzz = fuzz =
string("~") string("~")
|> ignore() |> ignore()
@ -24,6 +28,7 @@ defmodule Search.FloatParser do
float |> concat(fuzz) |> concat(unsigned_float) |> reduce(:range) |> unwrap_and_tag(:float_range), float |> concat(fuzz) |> concat(unsigned_float) |> reduce(:range) |> unwrap_and_tag(:float_range),
float |> unwrap_and_tag(:float) float |> unwrap_and_tag(:float)
]) ])
|> repeat(space)
|> eos() |> eos()
|> label("a real number, like `2.7182818' or `-10'") |> label("a real number, like `2.7182818' or `-10'")

View file

@ -2,6 +2,10 @@ defmodule Search.IntParser do
import NimbleParsec import NimbleParsec
import Search.Helpers import Search.Helpers
space =
choice([string(" "), string("\t"), string("\n"), string("\r"), string("\v"), string("\f")])
|> ignore()
fuzz = fuzz =
string("~") string("~")
|> ignore() |> ignore()
@ -17,6 +21,7 @@ defmodule Search.IntParser do
int |> concat(fuzz) |> integer(min: 1) |> reduce(:range) |> unwrap_and_tag(:int_range), int |> concat(fuzz) |> integer(min: 1) |> reduce(:range) |> unwrap_and_tag(:int_range),
int |> unwrap_and_tag(:int) int |> unwrap_and_tag(:int)
]) ])
|> repeat(space)
|> eos() |> eos()
|> label("an integer, like `3' or `-10'") |> label("an integer, like `3' or `-10'")

View file

@ -124,12 +124,17 @@ defmodule Search.IpParser do
]) ])
|> reduce({List, :to_string, []}) |> reduce({List, :to_string, []})
space =
choice([string(" "), string("\t"), string("\n"), string("\r"), string("\v"), string("\f")])
|> ignore()
ip = ip =
choice([ choice([
ipv4_address |> optional(ipv4_prefix), ipv4_address |> optional(ipv4_prefix),
ipv6_address |> optional(ipv6_prefix) ipv6_address |> optional(ipv6_prefix)
]) ])
|> reduce({Enum, :join, []}) |> reduce({Enum, :join, []})
|> repeat(space)
|> unwrap_and_tag(:ip) |> unwrap_and_tag(:ip)
|> eos() |> eos()
|> label("a valid IPv4 or IPv6 address and optional CIDR prefix") |> label("a valid IPv4 or IPv6 address and optional CIDR prefix")

View file

@ -192,29 +192,29 @@ defmodule Search.Parser do
# Types which do not support ranges # Types which do not support ranges
defp field_type(parser, [{LiteralParser, field_name}, range: :eq, literal: value]), 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]), 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: "*"]), defp field_type(_parser, [{LiteralParser, _field_name}, range: :eq, wildcard: "*"]),
do: {:ok, {%{match_all: %{}}, []}} do: {:ok, {%{match_all: %{}}, []}}
defp field_type(parser, [{LiteralParser, field_name}, range: :eq, wildcard: value]), 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]), 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]), 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: "*"]), defp field_type(_parser, [{NgramParser, _field_name}, range: :eq, wildcard: "*"]),
do: {:ok, {%{match_all: %{}}, []}} do: {:ok, {%{match_all: %{}}, []}}
defp field_type(parser, [{NgramParser, field_name}, range: :eq, wildcard: value]), 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]), defp field_type(parser, [{BoolParser, field_name}, range: :eq, bool: value]),