Class: MongoidSphinx::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid_sphinx/index.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Index

Returns a new instance of Index.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/mongoid_sphinx/index.rb', line 5

def initialize(model)
  @name         = self.class.name_for model
  @model        = model
  @options      = model.index_options
  @source       = Riddle::Configuration::XMLSource.new( "#{core_name}_0", config.source_options[:type])
  if defined?(Rails)
    @source.xmlpipe_command = "RAILS_ENV=#{Rails.env} script/rails runner '#{model.to_s}.sphinx_stream'"
  else
    @source.xmlpipe_command = "script/runner '#{model.to_s}.sphinx_stream'"
  end
end

Instance Attribute Details

#modelObject

Returns the value of attribute model.



3
4
5
# File 'lib/mongoid_sphinx/index.rb', line 3

def model
  @model
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/mongoid_sphinx/index.rb', line 3

def name
  @name
end

#sourceObject

Returns the value of attribute source.



3
4
5
# File 'lib/mongoid_sphinx/index.rb', line 3

def source
  @source
end

Class Method Details

.name_for(model) ⇒ Object



25
26
27
# File 'lib/mongoid_sphinx/index.rb', line 25

def self.name_for(model)
  model.name.underscore.tr(':/\\', '_')
end

Instance Method Details

#core_nameObject



17
18
19
# File 'lib/mongoid_sphinx/index.rb', line 17

def core_name
  "#{name}_core"
end

#delta_nameObject



21
22
23
# File 'lib/mongoid_sphinx/index.rb', line 21

def delta_name
  "#{name}_delta"
end

#local_optionsObject



29
30
31
# File 'lib/mongoid_sphinx/index.rb', line 29

def local_options
  @options
end

#optionsObject



33
34
35
36
37
38
39
# File 'lib/mongoid_sphinx/index.rb', line 33

def options
  all_index_options = config.index_options.clone
  @options.keys.select { |key|
    MongoidSphinx::Configuration::IndexOptions.include?(key.to_s)
  }.each { |key| all_index_options[key.to_sym] = @options[key] }
  all_index_options
end

#to_riddleObject



41
42
43
44
# File 'lib/mongoid_sphinx/index.rb', line 41

def to_riddle
  indexes = [to_riddle_for_core]
  indexes << to_riddle_for_distributed
end