class BooleanTermParser::Query
Attributes
must_not_terms[RW]
must_terms[RW]
should_terms[RW]
Public Class Methods
new(clauses)
click to toggle source
# File lib/doing/boolean_term_parser.rb, line 51 def initialize(clauses) grouped = clauses.chunk { |c| c.operator }.to_h self.should_terms = grouped.fetch(:should, []).map(&:term) self.must_not_terms = grouped.fetch(:must_not, []).map(&:term) self.must_terms = grouped.fetch(:must, []).map(&:term) end
Public Instance Methods
match(term)
click to toggle source
# File lib/doing/boolean_term_parser.rb, line 82 def match(term) term end
to_elasticsearch()
click to toggle source
# File lib/doing/boolean_term_parser.rb, line 58 def to_elasticsearch query = {} if should_terms.any? query[:should] = should_terms.map do |term| match(term) end end if must_terms.any? query[:must] = must_terms.map do |term| match(term) end end if must_not_terms.any? query[:must_not] = must_not_terms.map do |term| match(term) end end query end