class NoSE::Backend::Backend::IndexLookupStatementStep
Look up data on an index in the backend
Public Class Methods
new(client, _select, _conditions, step, next_step, prev_step)
click to toggle source
# File lib/nose/backend.rb, line 148 def initialize(client, _select, _conditions, step, next_step, prev_step) @client = client @step = step @index = step.index @prev_step = prev_step @next_step = next_step @eq_fields = step.eq_filter @range_field = step.range_filter end
Protected Instance Methods
expand_selected_fields(select)
click to toggle source
Decide which fields should be selected
# File lib/nose/backend.rb, line 188 def expand_selected_fields(select) # We just pick whatever is contained in the index that is either # mentioned in the query or required for the next lookup # TODO: Potentially try query.all_fields for those not required # It should be sufficient to check what is needed for future # filtering and sorting and use only those + query.select select += @next_step.index.hash_fields \ unless @next_step.nil? || !@next_step.is_a?(Plans::IndexLookupPlanStep) select &= @step.index.all_fields select end
initial_results(conditions)
click to toggle source
Get lookup values from the query for the first step
# File lib/nose/backend.rb, line 163 def initial_results(conditions) [Hash[conditions.map do |field_id, condition| fail if condition.value.nil? [field_id, condition.value] end]] end
result_conditions(conditions, results)
click to toggle source
Construct a list of conditions from the results
# File lib/nose/backend.rb, line 171 def result_conditions(conditions, results) results.map do |result| result_condition = @eq_fields.map do |field| Condition.new field, :'=', result[field.id] end unless @range_field.nil? operator = conditions.each_value.find(&:range?).operator result_condition << Condition.new(@range_field, operator, result[@range_field.id]) end result_condition end end