diff --git a/lib/philomena/search/lexer.ex b/lib/philomena/search/lexer.ex index cd430e37..ebe7a90c 100644 --- a/lib/philomena/search/lexer.ex +++ b/lib/philomena/search/lexer.ex @@ -181,11 +181,13 @@ defmodule Philomena.Search.Lexer do ]) |> reduce({List, :to_string, []}) + # choice([ + # , ip_address = - #choice([ - ipv4_address |> optional(ipv4_prefix)#, - #ipv6_address |> optional(ipv6_prefix) - #]) + ipv4_address + |> optional(ipv4_prefix) + # ipv6_address |> optional(ipv6_prefix) + # ]) |> reduce({Enum, :join, []}) |> label("a valid IPv4 or IPv6 address and optional CIDR prefix") |> unwrap_and_tag(:ip) diff --git a/lib/philomena/search/parser.ex b/lib/philomena/search/parser.ex index 917501ac..7454d468 100644 --- a/lib/philomena/search/parser.ex +++ b/lib/philomena/search/parser.ex @@ -120,15 +120,37 @@ defmodule Philomena.Search.Parser do defp search_fuzz(ctx, tokens) do case tokens do [{:int_field, field}, {:eq, _}, {:int, value}, {:fuzz, _}, {:number, fuzz} | r_tokens] -> - {%{range: %{try_alias(field) => %{gte: trunc(value - fuzz), lte: trunc(value + fuzz)}}}, r_tokens} + {%{ + range: %{try_alias(field) => %{gte: trunc(value - fuzz), lte: trunc(value + fuzz)}} + }, r_tokens} - [{:float_field, field}, {:eq, _}, {:float, value}, {:fuzz, _}, {:number, fuzz} | r_tokens] -> - {%{range: %{try_alias(field) => %{gte: trunc(value - fuzz), lte: trunc(value + fuzz)}}}, r_tokens} + [ + {:float_field, field}, + {:eq, _}, + {:float, value}, + {:fuzz, _}, + {:number, fuzz} | r_tokens + ] -> + {%{ + range: %{try_alias(field) => %{gte: trunc(value - fuzz), lte: trunc(value + fuzz)}} + }, r_tokens} - [{:literal_field, field}, {:eq, _}, {:text, value}, {:fuzz, _}, {:number, fuzz} | r_tokens] -> + [ + {:literal_field, field}, + {:eq, _}, + {:text, value}, + {:fuzz, _}, + {:number, fuzz} | r_tokens + ] -> {%{fuzzy: %{try_alias(field) => %{value: value, fuzziness: fuzz}}}, r_tokens} - [{:ngram_field, field}, {:eq, _}, {:text, value}, {:fuzz, _}, {:number, fuzz} | r_tokens] -> + [ + {:ngram_field, field}, + {:eq, _}, + {:text, value}, + {:fuzz, _}, + {:number, fuzz} | r_tokens + ] -> {%{fuzzy: %{try_alias(field) => %{value: value, fuzziness: fuzz}}}, r_tokens} [{:default, [text: value]}, {:fuzz, _}, {:number, fuzz} | r_tokens] ->