From b5a9660fd0dff46f7b7c493316e84e82c6a939b1 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Mon, 26 Aug 2019 20:00:48 -0400 Subject: [PATCH] format --- lib/philomena/search/lexer.ex | 10 ++++++---- lib/philomena/search/parser.ex | 32 +++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 9 deletions(-) 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] ->