Class: Neo4j::Core::Index::IndexConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/neo4j-core/index/index_config.rb

Overview

Responsible for holding the configuration for one index Is used in a DSL to configure the index.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entity_type) ⇒ IndexConfig

Returns a new instance of IndexConfig.

Parameters:

  • entity_type (:rel, :node)

    the type of index



11
12
13
14
15
16
# File 'lib/neo4j-core/index/index_config.rb', line 11

def initialize(entity_type)
  @entity_type = entity_type
  @_index_type = {}
  @_field_types = {}
  @_trigger_on = {}
end

Instance Attribute Details

#_field_typesObject (readonly)

Returns the value of attribute _field_types.



8
9
10
# File 'lib/neo4j-core/index/index_config.rb', line 8

def _field_types
  @_field_types
end

#_index_namesObject (readonly)

Returns the value of attribute _index_names.



8
9
10
# File 'lib/neo4j-core/index/index_config.rb', line 8

def _index_names
  @_index_names
end

#_index_typeObject (readonly)

Returns the value of attribute _index_type.



8
9
10
# File 'lib/neo4j-core/index/index_config.rb', line 8

def _index_type
  @_index_type
end

#_trigger_onObject (readonly)

Returns the value of attribute _trigger_on.



8
9
10
# File 'lib/neo4j-core/index/index_config.rb', line 8

def _trigger_on
  @_trigger_on
end

#entity_typeObject (readonly)

Returns the value of attribute entity_type.



8
9
10
# File 'lib/neo4j-core/index/index_config.rb', line 8

def entity_type
  @entity_type
end

Instance Method Details

#_prefix_index_nameObject



74
75
76
# File 'lib/neo4j-core/index/index_config.rb', line 74

def _prefix_index_name
  @prefix_index_name_block.nil? ? "" : @prefix_index_name_block.call
end

#decl_type_on(prop) ⇒ Class?

Returns the specified type of the property or nil.

Returns:

  • (Class, nil)

    the specified type of the property or nil

See Also:

  • #decl_type


55
56
57
# File 'lib/neo4j-core/index/index_config.rb', line 55

def decl_type_on(prop)
  @_field_types[prop]
end

#field_type(key) ⇒ Object



36
37
38
# File 'lib/neo4j-core/index/index_config.rb', line 36

def field_type(key)
  @_field_types[key.to_s]
end

#fieldsObject



95
96
97
# File 'lib/neo4j-core/index/index_config.rb', line 95

def fields
  @_index_type.keys
end

#has_index_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/neo4j-core/index/index_config.rb', line 91

def has_index_type?(type)
  @_index_type.values.include?(type)
end

#index(args) ⇒ Object

Specifies an index with configuration Used in the Index DSL.

Parameters:

  • args (Hash)

    the field and its configuration

See Also:



44
45
46
47
48
49
50
51
# File 'lib/neo4j-core/index/index_config.rb', line 44

def index(args)
  conf = args.last.kind_of?(Hash) ? args.pop : {}

  args.uniq.each do |field|
    @_index_type[field.to_s] = conf[:type] || :exact
    @_field_types[field.to_s] = conf[:field_type] || String
  end
end

#index?(field) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/neo4j-core/index/index_config.rb', line 99

def index?(field)
  @_index_type.include?(field.to_s)
end

#index_name_for_type(type) ⇒ Object

Returns the index name for the lucene index given a type.

Returns:

  • the index name for the lucene index given a type



65
66
67
# File 'lib/neo4j-core/index/index_config.rb', line 65

def index_name_for_type(type)
  _prefix_index_name + @_index_names[type]
end

#index_names(hash) ⇒ Object



78
79
80
# File 'lib/neo4j-core/index/index_config.rb', line 78

def index_names(hash)
  @_index_names = hash
end

#index_type(field) ⇒ Object



87
88
89
# File 'lib/neo4j-core/index/index_config.rb', line 87

def index_type(field)
  @_index_type[field.to_s]
end

#inherit_from(clazz) ⇒ Object



22
23
24
25
26
27
# File 'lib/neo4j-core/index/index_config.rb', line 22

def inherit_from(clazz)
  c = clazz._indexer.config
  raise "Can't inherit from different index type #{@entity_type} != #{c.entity_type}" if @entity_type != c.entity_type
  @_index_type.merge!(c._index_type)
  @_field_types.merge!(c._field_types)
end

#numeric?(field) ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
106
# File 'lib/neo4j-core/index/index_config.rb', line 103

def numeric?(field)
  raise "No index on #{field.inspect}, has fields: #{@field_types.inspect}" unless @_field_types[field]
  @_field_types[field] != String
end

#prefix_index_name(&block) ⇒ Object

Defines the



70
71
72
# File 'lib/neo4j-core/index/index_config.rb', line 70

def prefix_index_name(&block)
  @prefix_index_name_block = block
end

#rm_index_configObject



82
83
84
85
# File 'lib/neo4j-core/index/index_config.rb', line 82

def rm_index_config
  @_index_type = {}
  @_field_types = {}
end

#to_sObject



18
19
20
# File 'lib/neo4j-core/index/index_config.rb', line 18

def to_s
  "IndexConfig [#@entity_type, _index_type: #{@_index_type.inspect}, _field_types: #{@_field_types.inspect}, _trigger_on: #{@_trigger_on.inspect}]"
end

#trigger_on(hash) ⇒ Object

Specifies which property and values the index should be triggered on. Used in the Index DSL.



32
33
34
# File 'lib/neo4j-core/index/index_config.rb', line 32

def trigger_on(hash)
  merge_and_to_string(@_trigger_on, hash)
end

#trigger_on?(props) ⇒ true, false

Returns if the props can/should trigger an index operation.

Returns:

  • (true, false)

    if the props can/should trigger an index operation



60
61
62
# File 'lib/neo4j-core/index/index_config.rb', line 60

def trigger_on?(props)
  @_trigger_on.each_pair { |k, v| break true if (a = props[k]) && (v.include?(a)) } == true
end