Class: ODBA::Index
- Inherits:
-
IndexCommon
- Object
- IndexCommon
- ODBA::Index
- Defined in:
- lib/odba/index.rb
Overview
Currently there are 3 predefined Index-classes For Sample Code see http://dev.ywesee.com/wiki.php/ODBA/SimpleIndex http://dev.ywesee.com/wiki.php/ODBA/ConditionIndex http://dev.ywesee.com/wiki.php/ODBA/FulltextIndex
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
-
#fetch_ids(search_term, meta = nil) ⇒ Object
:nodoc:.
-
#initialize(index_definition, origin_module) ⇒ Index
constructor
:nodoc: all.
- #search_terms(origin) ⇒ Object
-
#update_origin(object) ⇒ Object
:nodoc:.
Methods inherited from IndexCommon
#current_origin_ids, #current_target_ids, #delete, #delete_origin, #delete_target, #do_update_index, #fill, #keys, #matches, #origin_class?, #proc_instance_origin, #proc_instance_target, #proc_resolve_search_term, #search_term, #set_relevance, #update, #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
Instance Method Details
#fetch_ids(search_term, meta = nil) ⇒ Object
:nodoc:
243 244 245 246 247 248 249 250 251 |
# File 'lib/odba/index.rb', line 243 def fetch_ids(search_term, = nil) # :nodoc: exact = .respond_to?(:exact) && .exact limit = .respond_to?(:limit) && .limit rows = ODBA.storage.retrieve_from_index(@index_name, search_term.to_s.downcase, exact, limit) set_relevance(, rows) rows.collect { |row| row.at(0) } end |
#search_terms(origin) ⇒ Object
293 294 295 |
# File 'lib/odba/index.rb', line 293 def search_terms(origin) super.collect { |term| term.to_s.downcase }.uniq end |
#update_origin(object) ⇒ Object
:nodoc:
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/odba/index.rb', line 253 def update_origin(object) # :nodoc: # Possible changes: # - search_terms of origin have changed # - targets have changed, except if @resolve_target == :none # => we need a matrix of all current [term, target_id] # and of all new [term, target_id] origin_id = object.odba_id search_terms = search_terms(object) current = current_target_ids(origin_id) target_ids = if @resolve_target == :none current.dup else proc_instance_target.call(object).collect { |obj| obj.odba_id } end target_ids.compact! target_ids.uniq! current_ids = [] current_terms = [] current.each { |row| current_ids.push(row[0]) current_terms.push(row[1]) } current_ids.uniq! current_terms.uniq! current_combinations = current_ids.each_with_object([]) { |id, memo| current_terms.each { |term| memo.push [term, id] } } combinations = target_ids.each_with_object([]) { |id, memo| search_terms.each { |term| memo.push [term, id] } } (current_combinations - combinations).each { |pair| delete_target(origin_id, *pair) } (combinations - current_combinations).each { |pair| do_update_index(origin_id, *pair) } end |