class RediSearch::Search::Clauses::Where

Attributes

field[R]
prior_clause[R]
term[R]

Public Class Methods

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

  initialize_term(condition)
end

Public Instance Methods

not(condition) click to toggle source
# File lib/redi_search/search/clauses/where.rb, line 26
def not(condition)
  @not = true

  initialize_term(condition)

  search
end
to_s() click to toggle source
# File lib/redi_search/search/clauses/where.rb, line 17
def to_s
  [
    prior_clause,
    "(#{not_operator}@#{field}:#{queryify_term})"
  ].compact.join(" ")
end

Private Instance Methods

condition?(condition) click to toggle source
# File lib/redi_search/search/clauses/where.rb, line 69
def condition?(condition)
  if condition.respond_to?(:empty?)
    condition.empty?
  else
    !condition
  end
end
initialize_term(condition) click to toggle source
# File lib/redi_search/search/clauses/where.rb, line 52
def initialize_term(condition)
  return if condition?(condition)

  condition, *options = condition.to_a

  @field = condition[0]
  @term = make_term(condition, options)
end
make_term(condition, options) click to toggle source
# File lib/redi_search/search/clauses/where.rb, line 61
def make_term(condition, options)
  if condition[1].is_a? RediSearch::Search
    condition[1]
  else
    Term.new(condition[1], **options.to_h)
  end
end
not_operator() click to toggle source
# File lib/redi_search/search/clauses/where.rb, line 46
def not_operator
  return "" unless @not

  "-"
end
queryify_term() click to toggle source
# File lib/redi_search/search/clauses/where.rb, line 38
def queryify_term
  if term.is_a? RediSearch::Search
    "(#{term.term_clause})"
  else
    term.to_s
  end
end