Class: Neo4j::Core::Index::IndexConfig
- Inherits:
-
Object
- Object
- Neo4j::Core::Index::IndexConfig
- 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
-
#_field_types ⇒ Object
readonly
Returns the value of attribute _field_types.
-
#_index_names ⇒ Object
readonly
Returns the value of attribute _index_names.
-
#_index_type ⇒ Object
readonly
Returns the value of attribute _index_type.
-
#_trigger_on ⇒ Object
readonly
Returns the value of attribute _trigger_on.
-
#entity_type ⇒ Object
readonly
Returns the value of attribute entity_type.
Instance Method Summary collapse
- #_prefix_index_name ⇒ Object
-
#decl_type_on(prop) ⇒ Class?
The specified type of the property or nil.
- #field_type(key) ⇒ Object
- #fields ⇒ Object
- #has_index_type?(type) ⇒ Boolean
-
#index(args) ⇒ Object
Specifies an index with configuration Used in the Index DSL.
- #index?(field) ⇒ Boolean
-
#index_name_for_type(type) ⇒ Object
The index name for the lucene index given a type.
- #index_names(hash) ⇒ Object
- #index_type(field) ⇒ Object
- #inherit_from(clazz) ⇒ Object
-
#initialize(entity_type) ⇒ IndexConfig
constructor
A new instance of IndexConfig.
- #numeric?(field) ⇒ Boolean
-
#prefix_index_name(&block) ⇒ Object
Defines the.
- #rm_index_config ⇒ Object
- #to_s ⇒ Object
-
#trigger_on(hash) ⇒ Object
Specifies which property and values the index should be triggered on.
-
#trigger_on?(props) ⇒ true, false
If the props can/should trigger an index operation.
Constructor Details
#initialize(entity_type) ⇒ IndexConfig
Returns a new instance of IndexConfig.
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_types ⇒ Object (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_names ⇒ Object (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_type ⇒ Object (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_on ⇒ Object (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_type ⇒ Object (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_name ⇒ Object
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.
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 |
#fields ⇒ Object
95 96 97 |
# File 'lib/neo4j-core/index/index_config.rb', line 95 def fields @_index_type.keys end |
#has_index_type?(type) ⇒ 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.
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
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.
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
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_config ⇒ Object
82 83 84 85 |
# File 'lib/neo4j-core/index/index_config.rb', line 82 def rm_index_config @_index_type = {} @_field_types = {} end |
#to_s ⇒ Object
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.
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 |