class NoSE::Backend::FileBackend::IndexLookupStatementStep

Look up data on an index in the backend

Public Instance Methods

process(conditions, results) click to toggle source

Filter all the rows in the specified index to those requested

# File lib/nose/backend/file.rb, line 113
def process(conditions, results)
  # Get the set of conditions we need to process
  results = initial_results(conditions) if results.nil?
  condition_list = result_conditions conditions, results

  # Loop through all rows to find the matching ones
  rows = @client[@index.key] || []
  selected = condition_list.flat_map do |condition|
    rows.select { |row| row_matches? row, condition }
  end.compact

  # Apply the limit and only return selected fields
  field_ids = Set.new @step.fields.map(&:id).to_set
  selected[0..(@step.limit.nil? ? -1 : @step.limit)].map do |row|
    row.select { |k, _| field_ids.include? k }
  end
end