mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 14:57:59 +01:00
require spaces around textual search operators, fixes #37
This commit is contained in:
parent
f6f29840ca
commit
8dae60de92
1 changed files with 26 additions and 11 deletions
|
@ -3,6 +3,10 @@ defmodule Search.Lexer do
|
||||||
|
|
||||||
defp to_number(input), do: Search.Helpers.to_number(input)
|
defp to_number(input), do: Search.Helpers.to_number(input)
|
||||||
|
|
||||||
|
space =
|
||||||
|
choice([string(" "), string("\t"), string("\n"), string("\r"), string("\v"), string("\f")])
|
||||||
|
|> ignore()
|
||||||
|
|
||||||
float =
|
float =
|
||||||
optional(ascii_char('-+'))
|
optional(ascii_char('-+'))
|
||||||
|> ascii_string([?0..?9], min: 1)
|
|> ascii_string([?0..?9], min: 1)
|
||||||
|
@ -11,24 +15,33 @@ defmodule Search.Lexer do
|
||||||
|> reduce(:to_number)
|
|> reduce(:to_number)
|
||||||
|
|
||||||
l_and =
|
l_and =
|
||||||
choice([string("AND"), string("&&"), string(",")])
|
times(space, min: 1)
|
||||||
|
|> choice([string("AND"), string("&&")])
|
||||||
|
|> times(space, min: 1)
|
||||||
|
|> unwrap_and_tag(:and)
|
||||||
|
|
||||||
|
l_comma =
|
||||||
|
string(",")
|
||||||
|> unwrap_and_tag(:and)
|
|> unwrap_and_tag(:and)
|
||||||
|
|
||||||
l_or =
|
l_or =
|
||||||
choice([string("OR"), string("||")])
|
times(space, min: 1)
|
||||||
|
|> choice([string("OR"), string("||")])
|
||||||
|
|> times(space, min: 1)
|
||||||
|> unwrap_and_tag(:or)
|
|> unwrap_and_tag(:or)
|
||||||
|
|
||||||
l_not =
|
l_not =
|
||||||
choice([string("NOT"), string("!"), string("-")])
|
string("NOT")
|
||||||
|
|> times(space, min: 1)
|
||||||
|
|> unwrap_and_tag(:not)
|
||||||
|
|
||||||
|
l_negate =
|
||||||
|
choice([string("!"), string("-")])
|
||||||
|> unwrap_and_tag(:not)
|
|> unwrap_and_tag(:not)
|
||||||
|
|
||||||
lparen = string("(") |> unwrap_and_tag(:lparen)
|
lparen = string("(") |> unwrap_and_tag(:lparen)
|
||||||
rparen = string(")") |> unwrap_and_tag(:rparen)
|
rparen = string(")") |> unwrap_and_tag(:rparen)
|
||||||
|
|
||||||
space =
|
|
||||||
choice([string(" "), string("\t"), string("\n"), string("\r"), string("\v"), string("\f")])
|
|
||||||
|> ignore()
|
|
||||||
|
|
||||||
quot = string("\"")
|
quot = string("\"")
|
||||||
|
|
||||||
boost =
|
boost =
|
||||||
|
@ -37,12 +50,12 @@ defmodule Search.Lexer do
|
||||||
|> unwrap_and_tag(:boost)
|
|> unwrap_and_tag(:boost)
|
||||||
|
|
||||||
stop_words =
|
stop_words =
|
||||||
repeat(space)
|
choice([
|
||||||
|> choice([
|
l_comma,
|
||||||
l_and,
|
l_and,
|
||||||
l_or,
|
l_or,
|
||||||
rparen,
|
repeat(space) |> concat(rparen),
|
||||||
boost
|
repeat(space) |> concat(boost)
|
||||||
])
|
])
|
||||||
|
|
||||||
defcombinatorp(
|
defcombinatorp(
|
||||||
|
@ -85,6 +98,8 @@ defmodule Search.Lexer do
|
||||||
|
|
||||||
outer =
|
outer =
|
||||||
choice([
|
choice([
|
||||||
|
l_comma,
|
||||||
|
l_negate,
|
||||||
l_and,
|
l_and,
|
||||||
l_or,
|
l_or,
|
||||||
l_not,
|
l_not,
|
||||||
|
|
Loading…
Reference in a new issue