Module: Pacer::PacerGraph::KeyIndices

Included in:
Pacer::PacerGraph
Defined in:
lib/pacer/graph/pacer_graph.rb

Instance Method Summary collapse

Instance Method Details

#build_key_index_parameters_from(option_hash) ⇒ Object



422
423
424
425
426
# File 'lib/pacer/graph/pacer_graph.rb', line 422

def build_key_index_parameters_from(option_hash)
  option_hash.each_with_object([]) do |(key, value), params|
    params << Pacer::Parameter.new(key, value)
  end
end

#create_key_index(name, type = :vertex, opts = {}) ⇒ Object



371
372
373
374
375
376
377
378
379
380
381
# File 'lib/pacer/graph/pacer_graph.rb', line 371

def create_key_index(name, type = :vertex, opts = {})
  return if key_indices(type).include? name.to_s
  params = build_key_index_parameters_from opts
  if features.supportsKeyIndices
    if element_type(type) == :vertex and features.supportsVertexKeyIndex
      blueprints_graph.createKeyIndex name.to_s, index_class(:vertex), *params
    elsif element_type(type) == :edge and features.supportsEdgeKeyIndex
      blueprints_graph.createKeyIndex name.to_s, index_class(:edge), *params
    end
  end
end

#drop_key_index(name, type = :vertex) ⇒ Object



383
384
385
386
387
388
389
390
391
# File 'lib/pacer/graph/pacer_graph.rb', line 383

def drop_key_index(name, type = :vertex)
  if features.supportsKeyIndices
    if element_type(type) == :vertex and features.supportsVertexKeyIndex
      blueprints_graph.dropKeyIndex name.to_s, index_class(:vertex)
    elsif element_type(type) == :edge and features.supportsEdgeKeyIndex
      blueprints_graph.createKeyIndex name.to_s, index_class(:edge)
    end
  end
end

#edges_by_key(key, value, *extensions) ⇒ Object



412
413
414
415
416
417
418
419
420
# File 'lib/pacer/graph/pacer_graph.rb', line 412

def edges_by_key(key, value, *extensions)
  if key_indices(:edge).include? key.to_s
    pipe = Pacer::Pipes::WrappingPipe.new self, :edge, extensions
    pipe.setStarts blueprints_graph.getEdges(key.to_s, value).iterator
    pipe
  else
    fail ClientError, "The key #{ key } is not indexed"
  end
end

#key_indices(type = :vertex) ⇒ Object



393
394
395
396
397
398
399
400
# File 'lib/pacer/graph/pacer_graph.rb', line 393

def key_indices(type = :vertex)
  # will raise internal error if not one of :edge or :vertex
  if features.supportsKeyIndices
    blueprints_graph.getIndexedKeys(index_class(type)).to_set
  else
    []
  end
end

#vertices_by_key(key, value, *extensions) ⇒ Object



402
403
404
405
406
407
408
409
410
# File 'lib/pacer/graph/pacer_graph.rb', line 402

def vertices_by_key(key, value, *extensions)
  if key_indices(:vertex).include? key.to_s
    pipe = Pacer::Pipes::WrappingPipe.new self, :vertex, extensions
    pipe.setStarts blueprints_graph.getVertices(key.to_s, value).iterator
    pipe
  else
    fail ClientError, "The key #{ key } is not indexed"
  end
end