Class: Picky::Indexes

Inherits:
Object show all
Extended by:
Helpers::Indexing
Includes:
Helpers::Indexing
Defined in:
lib/picky/indexes.rb,
lib/picky/indexes_indexed.rb,
lib/picky/indexes_indexing.rb,
lib/picky/indexes_convenience.rb

Overview

Indexes indexing.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Indexing

index, timed_indexing

Methods included from Helpers::Measuring

#timed

Constructor Details

#initialize(*indexes) ⇒ Indexes

Returns a new instance of Indexes.



26
27
28
29
# File 'lib/picky/indexes.rb', line 26

def initialize *indexes
  clear_indexes
  indexes.each { |index| register index }
end

Instance Attribute Details

#index_mappingObject (readonly)

Returns the value of attribute index_mapping.



11
12
13
# File 'lib/picky/indexes.rb', line 11

def index_mapping
  @index_mapping
end

#indexesObject (readonly)

Returns the value of attribute indexes.



11
12
13
# File 'lib/picky/indexes.rb', line 11

def indexes
  @indexes
end

Class Method Details

.identifierObject



36
37
38
# File 'lib/picky/indexes.rb', line 36

def self.identifier
  name
end

.index(scheduler = Scheduler.new) ⇒ Object

Overrides index from the helper.



16
17
18
19
20
# File 'lib/picky/indexes_indexing.rb', line 16

def self.index scheduler = Scheduler.new
  timed_indexing scheduler do
    instance.index scheduler
  end
end

.instanceObject

Return the Indexes instance.



33
34
35
# File 'lib/picky/indexes.rb', line 33

def self.instance
  @instance ||= new
end

.optimize_memory(array_references = Hash.new) ⇒ Object



55
56
57
# File 'lib/picky/indexes.rb', line 55

def self.optimize_memory array_references = Hash.new
  self.instance.optimize_memory array_references
end

.register(index) ⇒ Object



68
69
70
# File 'lib/picky/indexes.rb', line 68

def self.register index
  self.instance.register index
end

Instance Method Details

#[](identifier) ⇒ Object

Extracts an index, given its identifier.



74
75
76
77
# File 'lib/picky/indexes.rb', line 74

def [] identifier
  index_name = identifier.intern
  index_mapping[index_name] || raise_not_found(index_name)
end

#clear_indexesObject

Clears the indexes and the mapping.



42
43
44
45
# File 'lib/picky/indexes.rb', line 42

def clear_indexes
  @indexes       = []
  @index_mapping = Hash.new
end

#optimize_memory(array_references = Hash.new) ⇒ Object

Tries to optimize the memory usage of the indexes.



49
50
51
52
53
54
# File 'lib/picky/indexes.rb', line 49

def optimize_memory array_references = Hash.new
  dedup = Picky::Optimizers::Memory::ArrayDeduplicator.new
  @indexes.each do |index|
    index.optimize_memory array_references
  end
end

#raise_not_found(index_name) ⇒ Object

Raises a not found for the index.



81
82
83
# File 'lib/picky/indexes.rb', line 81

def raise_not_found index_name
  raise %Q{Index "#{index_name}" not found. Possible indexes: "#{indexes.map(&:name).join('", "')}".}
end

#register(index) ⇒ Object

Registers an index with the indexes.



61
62
63
64
65
66
67
# File 'lib/picky/indexes.rb', line 61

def register index
  # TODO Do not store duplicate indexes.
  #
  # self.indexes.delete_if { |existing| existing.name == index.name }
  self.indexes << index
  self.index_mapping[index.name] = index
end

#to_sObject



87
88
89
# File 'lib/picky/indexes.rb', line 87

def to_s
  indexes.indented_to_s
end

#tokenizerObject



24
25
26
# File 'lib/picky/indexes_indexing.rb', line 24

def tokenizer
  Tokenizer.indexing
end