Class: ODBA::ConditionIndex
- Inherits:
-
IndexCommon
- Object
- IndexCommon
- ODBA::ConditionIndex
- Defined in:
- lib/odba/index.rb
Overview
:nodoc: all
Constant Summary
Constants included from Persistable
Persistable::Exact, Persistable::Find, Persistable::ODBA_EXCLUDE_VARS, Persistable::ODBA_INDEXABLE, Persistable::ODBA_PREDEFINE_EXCLUDE_VARS, Persistable::ODBA_PREDEFINE_SERIALIZABLE, Persistable::ODBA_PREFETCH, Persistable::ODBA_SERIALIZABLE
Instance Attribute Summary
Attributes inherited from IndexCommon
#class_filter, #index_name, #origin_klass, #resolve_origin, #resolve_search_term, #resolve_target, #target_klass
Attributes included from Persistable
#odba_id, #odba_name, #odba_persistent, #odba_prefetch
Instance Method Summary collapse
- #current_ids(rows, id_name) ⇒ Object
- #current_origin_ids(target_id) ⇒ Object
- #current_target_ids(origin_id) ⇒ Object
- #delete_origin(origin_id, search_terms) ⇒ Object
- #delete_target(origin_id, search_terms, target_id) ⇒ Object
-
#do_update_index(origin_id, search_terms, target_id = nil) ⇒ Object
:nodoc:.
-
#fetch_ids(conditions, meta = nil) ⇒ Object
:nodoc:.
-
#initialize(index_definition, origin_module) ⇒ ConditionIndex
constructor
:nodoc:.
-
#proc_resolve_search_term ⇒ Object
:nodoc:.
- #search_terms(origin) ⇒ Object
Methods inherited from IndexCommon
#delete, #fill, #keys, #matches, #origin_class?, #proc_instance_origin, #proc_instance_target, #search_term, #set_relevance, #update, #update_origin, #update_target
Methods included from Persistable
#==, append_features, #dup, #eql?, #odba_add_observer, #odba_collection, #odba_cut_connection, #odba_delete, #odba_delete_observer, #odba_delete_observers, #odba_dup, #odba_exclude_vars, #odba_indexable?, #odba_isolated_dump, #odba_isolated_store, #odba_isolated_stub, #odba_isolated_twin, #odba_notify_observers, #odba_observers, #odba_potentials, #odba_prefetch?, #odba_replace!, #odba_replace_persistables, #odba_replace_stubs, #odba_restore, #odba_serializables, #odba_snapshot, #odba_store, #odba_store_unsaved, #odba_stubize, #odba_take_snapshot, #odba_target_ids, #odba_unsaved?, #odba_unsaved_neighbors, sanitize
Constructor Details
#initialize(index_definition, origin_module) ⇒ ConditionIndex
:nodoc:
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/odba/index.rb', line 299 def initialize(index_definition, origin_module) # :nodoc: super definition = {} @resolve_search_term = {} index_definition.resolve_search_term.each { |name, info| if info.is_a?(String) info = {"resolve" => info} end if info["type"].nil? info["type"] = "text" end @resolve_search_term.store(name, info) definition.store(name, info["type"]) } ODBA.storage.create_condition_index(@index_name, definition) end |
Instance Method Details
#current_ids(rows, id_name) ⇒ Object
316 317 318 319 320 321 322 323 324 325 |
# File 'lib/odba/index.rb', line 316 def current_ids(rows, id_name) rows.collect { |row| [ row[id_name], @resolve_search_term.keys.collect { |key| [key.to_s, row[key]] }.sort ] } end |
#current_origin_ids(target_id) ⇒ Object
327 328 329 330 331 332 |
# File 'lib/odba/index.rb', line 327 def current_origin_ids(target_id) current_ids(ODBA.storage.condition_index_ids(@index_name, target_id, "target_id"), "origin_id") end |
#current_target_ids(origin_id) ⇒ Object
334 335 336 337 338 339 |
# File 'lib/odba/index.rb', line 334 def current_target_ids(origin_id) current_ids(ODBA.storage.condition_index_ids(@index_name, origin_id, "origin_id"), "target_id") end |
#delete_origin(origin_id, search_terms) ⇒ Object
341 342 343 344 |
# File 'lib/odba/index.rb', line 341 def delete_origin(origin_id, search_terms) ODBA.storage.condition_index_delete(@index_name, origin_id, search_terms) end |
#delete_target(origin_id, search_terms, target_id) ⇒ Object
346 347 348 349 |
# File 'lib/odba/index.rb', line 346 def delete_target(origin_id, search_terms, target_id) ODBA.storage.condition_index_delete(@index_name, origin_id, search_terms, target_id) end |
#do_update_index(origin_id, search_terms, target_id = nil) ⇒ Object
:nodoc:
351 352 353 354 |
# File 'lib/odba/index.rb', line 351 def do_update_index(origin_id, search_terms, target_id = nil) # :nodoc: ODBA.storage.update_condition_index(@index_name, origin_id, search_terms, target_id) end |
#fetch_ids(conditions, meta = nil) ⇒ Object
:nodoc:
356 357 358 359 360 361 362 363 |
# File 'lib/odba/index.rb', line 356 def fetch_ids(conditions, = nil) # :nodoc: limit = .respond_to?(:limit) && .limit rows = ODBA.storage.retrieve_from_condition_index(@index_name, conditions, limit) set_relevance(, rows) rows.collect { |row| row.at(0) } end |
#proc_resolve_search_term ⇒ Object
:nodoc:
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/odba/index.rb', line 365 def proc_resolve_search_term # :nodoc: if @proc_resolve_search_term.nil? src = <<-EOS Proc.new { |origin| values = {} EOS @resolve_search_term.each { |name, info| src << <<-EOS begin values.store('#{name}', origin.#{info["resolve"]}) rescue NameError end EOS } src << <<-EOS values } EOS @proc_resolve_search_term = eval(src) end @proc_resolve_search_term end |
#search_terms(origin) ⇒ Object
388 389 390 |
# File 'lib/odba/index.rb', line 388 def search_terms(origin) super.collect { |data| data.to_a.sort } end |