class RediSearch::Search::Clauses::Boolean

Attributes

prior_clause[R]
term[R]

Public Class Methods

new(search, term, prior_clause = nil, **term_options) click to toggle source
# File lib/redi_search/search/clauses/boolean.rb, line 9
def initialize(search, term, prior_clause = nil, **term_options)
  @search = search
  @prior_clause = prior_clause
  @not = false

  initialize_term(term, **term_options) if term
end

Public Instance Methods

not(term, **term_options) click to toggle source
# File lib/redi_search/search/clauses/boolean.rb, line 25
def not(term, **term_options)
  @not = true

  initialize_term(term, **term_options) if term

  search
end
to_s() click to toggle source
# File lib/redi_search/search/clauses/boolean.rb, line 17
def to_s
  raise ArgumentError, "missing query terms" unless term

  [prior_clause, queryify_term].compact.join(operand)
end

Private Instance Methods

initialize_term(term, **term_options) click to toggle source
# File lib/redi_search/search/clauses/boolean.rb, line 47
def initialize_term(term, **term_options)
  @term = if term.is_a? RediSearch::Search
            term
          else
            Term.new(term, **term_options)
          end
end
not_operator() click to toggle source
# File lib/redi_search/search/clauses/boolean.rb, line 41
def not_operator
  return "" unless @not

  "-"
end
operand() click to toggle source
# File lib/redi_search/search/clauses/boolean.rb, line 37
def operand
  raise NotImplementedError, "#{__method__} needs to be defined"
end
queryify_term() click to toggle source
# File lib/redi_search/search/clauses/boolean.rb, line 55
def queryify_term
  if term_is_search?
    queryify_search
  else
    term
  end.to_s.dup.prepend(not_operator)
end
term_is_search?() click to toggle source
# File lib/redi_search/search/clauses/boolean.rb, line 63
def term_is_search?
  term.is_a? RediSearch::Search
end