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 dev.ywesee.com/wiki.php/ODBA/SimpleIndex dev.ywesee.com/wiki.php/ODBA/ConditionIndex dev.ywesee.com/wiki.php/ODBA/FulltextIndex
Constant Summary
Constants inherited from IndexCommon
ODBA::IndexCommon::ODBA_EXCLUDE_VARS
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:
227 228 229 230 231 232 233 234 235 |
# File 'lib/odba/index.rb', line 227 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
276 277 278 |
# File 'lib/odba/index.rb', line 276 def search_terms(origin) super.collect { |term| term.to_s.downcase }.uniq end |
#update_origin(object) ⇒ Object
:nodoc:
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/odba/index.rb', line 236 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.inject([]) { |memo, id| current_terms.each { |term| memo.push [term, id] } memo } combinations = target_ids.inject([]) { |memo, id| search_terms.each { |term| memo.push [term, id] } memo } (current_combinations - combinations).each { |pair| delete_target(origin_id, *pair) } (combinations - current_combinations).each { |pair| do_update_index(origin_id, *pair) } end |