mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
format
This commit is contained in:
parent
a0fa66628a
commit
b5a9660fd0
2 changed files with 33 additions and 9 deletions
|
@ -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)
|
||||
|
|
|
@ -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] ->
|
||||
|
|
Loading…
Reference in a new issue