class NoSE::Backend::MongoBackend::IndexLookupStatementStep
A query step to look up data from a particular collection
Public Class Methods
new(client, select, conditions, step, next_step, prev_step)
click to toggle source
rubocop:disable Metrics/ParameterLists
Calls superclass method
NoSE::Backend::Backend::IndexLookupStatementStep::new
# File lib/nose/backend/mongo.rb, line 176 def initialize(client, select, conditions, step, next_step, prev_step) super @logger = Logging.logger['nose::backend::mongo::indexlookupstep'] @order = @step.order_by.map do |field| { MongoBackend.field_path(@index, field).join('.') => 1 } end end
Public Instance Methods
process(conditions, results)
click to toggle source
Perform a column family lookup in MongoDB
# File lib/nose/backend/mongo.rb, line 187 def process(conditions, results) results = initial_results(conditions) if results.nil? condition_list = result_conditions conditions, results new_result = condition_list.flat_map do |result_conditions| query_doc = query_doc_for_conditions result_conditions result = @client[@index.to_id_graph.key].find(query_doc) result = result.sort(*@order) unless @order.empty? result.to_a end # Limit the size of the results in case we fetched multiple keys new_result = new_result[0..(@step.limit.nil? ? -1 : @step.limit)] MongoBackend.rows_from_mongo new_result, @index, @step.fields end
Private Instance Methods
mongo_operator(operator)
click to toggle source
Produce the comparison operator used in MongoDB @return [String]
# File lib/nose/backend/mongo.rb, line 222 def mongo_operator(operator) case operator when :> '$gt' when :>= '$gte' when :< '$lt' when :<= '$lte' end end
query_doc_for_conditions(conditions)
click to toggle source
Produce the document used to issue the query to MongoDB @return [Hash]
# File lib/nose/backend/mongo.rb, line 208 def query_doc_for_conditions(conditions) conditions.map do |c| match = c.value match = BSON::ObjectId(match) if c.field.is_a? Fields::IDField # For range operators, find the corresponding MongoDB operator match = { mongo_operator(op) => match } if c.operator != :'=' { MongoBackend.field_path(@index, c.field).join('.') => match } end.reduce(&:merge) end