class Elasticfusion::Search::Query::Parser
Constants
- FIELD_QUALIFIERS
Public Class Methods
new(query, searchable_fields = [])
click to toggle source
# File lib/elasticfusion/search/query/parser.rb, line 9 def initialize(query, searchable_fields = []) @lexer = Lexer.new(query, searchable_fields) end
Public Instance Methods
ast()
click to toggle source
query = disjunction
;
disjunction = conjunction , [ ( “OR” | “|” ) , disjunction ]
;
conjunction = boolean clause , [ ( “AND” | “,” ) , conjunction ]
;
boolean clause = ( “NOT” | “-” ) , boolean clause
| clause ;
clause = parenthesized expression
| field term | term ;
parenthesized expression = “(” , disjunction , “)”
;
field term = field , “:” , [ field qualifier ] , safe string
;
term = quoted string
| string with balanced parentheses ;
# File lib/elasticfusion/search/query/parser.rb, line 38 def ast disjunction end
boolean_clause()
click to toggle source
# File lib/elasticfusion/search/query/parser.rb, line 76 def boolean_clause negation = match :not skip :whitespace if negation body = boolean_clause redundant_negation = body.is_a?(NegatedClause) if redundant_negation body.body else NegatedClause.new body end else clause end end
clause()
click to toggle source
# File lib/elasticfusion/search/query/parser.rb, line 94 def clause parenthesized_expression || field_term || term end
conjunction()
click to toggle source
# File lib/elasticfusion/search/query/parser.rb, line 59 def conjunction skip :whitespace left = boolean_clause skip :whitespace connective = match :and skip :whitespace right = conjunction if connective if right Expression.new :and, left, right else left end end
disjunction()
click to toggle source
# File lib/elasticfusion/search/query/parser.rb, line 42 def disjunction skip :whitespace left = conjunction skip :whitespace connective = match :or skip :whitespace right = disjunction if connective if right Expression.new :or, left, right else left end end
field_qualifier()
click to toggle source
# File lib/elasticfusion/search/query/parser.rb, line 138 def field_qualifier skip :whitespace qualifier = match :field_qualifier FIELD_QUALIFIERS[qualifier] end
field_term()
click to toggle source
# File lib/elasticfusion/search/query/parser.rb, line 113 def field_term field = match_field if field qualifier = field_qualifier skip :whitespace if qualifier field_query = safe_string FieldTerm.new field, qualifier, field_query end end
parenthesized_expression()
click to toggle source
# File lib/elasticfusion/search/query/parser.rb, line 98 def parenthesized_expression opening_parens = left_parentheses if opening_parens body = disjunction closing_parens = right_parentheses(opening_parens) if opening_parens == closing_parens body else raise ImbalancedParenthesesError end end end
term()
click to toggle source
# File lib/elasticfusion/search/query/parser.rb, line 127 def term string = quoted_string || string_with_balanced_parentheses Term.new string.downcase end