484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
|
# File 'lib/no_brainer/criteria/where.rb', line 484
def find_strategy_hidden_between
clauses = get_candidate_clauses(:gt, :ge, :lt, :le).group_by(&:key_path)
return nil unless clauses.present?
get_usable_indexes(:geo => false).each do |index|
matched_clauses = clauses[[index.name]].try(:select) { |c| c.compatible_with_index?(index) }
next unless matched_clauses.present?
op_clauses = Hash[matched_clauses.map { |c| [c.op, c] }]
left_bound = op_clauses[:gt] || op_clauses[:ge]
right_bound = op_clauses[:lt] || op_clauses[:le]
right_bound = nil if index.multi && left_bound && right_bound
options = {}
options[:left_bound] = {:gt => :open, :ge => :closed}[left_bound.op] if left_bound
options[:right_bound] = {:lt => :open, :le => :closed}[right_bound.op] if right_bound
return IndexStrategy.new(self, ast, [left_bound, right_bound].compact, index, :between,
[left_bound ? left_bound.try(:value) : RethinkDB::RQL.new.minval,
right_bound ? right_bound.try(:value) : RethinkDB::RQL.new.maxval], options)
end
return nil
end
|