Class: ODBA::ConditionIndex

Inherits:
IndexCommon show all
Defined in:
lib/odba/index.rb

Overview

:nodoc: all

Constant Summary

Constants inherited from IndexCommon

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

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:



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/odba/index.rb', line 281

def initialize(index_definition, origin_module) # :nodoc:
	super(index_definition, origin_module)
	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



297
298
299
300
301
302
303
304
305
# File 'lib/odba/index.rb', line 297

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



306
307
308
309
310
311
# File 'lib/odba/index.rb', line 306

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



312
313
314
315
316
317
# File 'lib/odba/index.rb', line 312

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



318
319
320
321
# File 'lib/odba/index.rb', line 318

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



322
323
324
325
# File 'lib/odba/index.rb', line 322

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:



326
327
328
329
# File 'lib/odba/index.rb', line 326

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:



330
331
332
333
334
335
336
337
# File 'lib/odba/index.rb', line 330

def fetch_ids(conditions, meta=nil)  # :nodoc:
	limit = meta.respond_to?(:limit) && meta.limit
	rows = ODBA.storage.retrieve_from_condition_index(@index_name, 
                                                      conditions, 
                                                      limit)
	set_relevance(meta, rows)
    rows.collect { |row| row.at(0) }
end

#proc_resolve_search_termObject

:nodoc:



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/odba/index.rb', line 338

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



360
361
362
# File 'lib/odba/index.rb', line 360

def search_terms(origin)
  super.collect { |data| data.to_a.sort }
end