Module: Pacer::PacerGraph::Indices

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

Instance Method Summary collapse

Instance Method Details

#drop_index(idx) ⇒ Object



306
307
308
309
310
311
312
313
# File 'lib/pacer/graph/pacer_graph.rb', line 306

def drop_index(idx)
  return drop_temp_index(idx) unless features.supportsIndices
  if idx.is_a? String or idx.is_a? Symbol
    blueprints_graph.dropIndex idx
  else
    blueprints_graph.dropIndex idx.indexName
  end
end

#drop_temp_index(idx) ⇒ Object



330
331
332
# File 'lib/pacer/graph/pacer_graph.rb', line 330

def drop_temp_index(idx)
  @temp_indices.delete idx.name
end

#drop_temp_indicesObject



334
335
336
# File 'lib/pacer/graph/pacer_graph.rb', line 334

def drop_temp_indices
  @temp_indices = {}
end

#index(name, type = nil, opts = {}) ⇒ Pacer::IndexMixin

Return an index by name.

Parameters:

  • name (#to_s)

    of the index

  • type (:vertex, :edge, element type) (defaults to: nil)

    guarantees that the index returned is of the type specified.

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :create (true)

    create the index if it doesn’t exist

Returns:

  • (Pacer::IndexMixin)


291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/pacer/graph/pacer_graph.rb', line 291

def index(name, type = nil, opts = {})
  return temp_index(name, type, opts) unless features.supportsIndices
  name = name.to_s
  if type
    type = index_class element_type type
    idx = blueprints_graph.getIndices.detect { |i| i.index_name == name }
    if idx.nil? and opts[:create]
      idx = blueprints_graph.createIndex name, type
    end
  else
    idx = blueprints_graph.getIndices.detect { |i| i.index_name == name }
  end
  Pacer::Wrappers::IndexWrapper.new self, idx, type if idx
end

#index_class(et) ⇒ Object

Return an object that can be compared to the return value of Index#index_class.



340
341
342
343
344
345
346
347
348
349
350
# File 'lib/pacer/graph/pacer_graph.rb', line 340

def index_class(et)
  type = case et
         when :vertex
           Pacer::Vertex
         when :edge
           Pacer::Edge
         else
           fail InternalError, "Unable to determine index class from #{ et.inspect }"
         end
  type.java_class.to_java
end

#index_class?(et, thing) ⇒ Boolean

Returns:

  • (Boolean)


352
353
354
355
356
357
358
# File 'lib/pacer/graph/pacer_graph.rb', line 352

def index_class?(et, thing)
  if thing.interface?
    index_class(et) == thing
  else
    thing.interfaces.include? index_class(et)
  end
end

#indicesObject



360
361
362
363
364
365
366
# File 'lib/pacer/graph/pacer_graph.rb', line 360

def indices
  if features.supportsIndices
    blueprints_graph.getIndices
  else
    []
  end
end

#temp_index(name, type = nil, opts = {}) ⇒ Object



315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/pacer/graph/pacer_graph.rb', line 315

def temp_index(name, type = nil, opts = {})
  @temp_indices ||= {}
  idx = @temp_indices[name]
  unless idx
    if opts[:temp] != false
      if name and type and opts[:create]
        idx = @temp_indices[name] = Pacer::Graph::HashIndex.new type, name
      elsif opts[:create]
        idx = Pacer::Graph::HashIndex.new type, nil
      end
    end
  end
  Pacer::Wrappers::IndexWrapper.new self, idx, idx.type if idx
end