class ThinkingSphinx::Index

Attributes

block[R]
options[R]
reference[R]

Public Class Methods

define(reference, options = {}, &block) click to toggle source
# File lib/thinking_sphinx/index.rb, line 6
def self.define(reference, options = {}, &block)
  new(reference, options, &block).indices.each do |index|
    ThinkingSphinx::Configuration.instance.indices << index
  end
end
new(reference, options, &block) click to toggle source
# File lib/thinking_sphinx/index.rb, line 12
def initialize(reference, options, &block)
  defaults = ThinkingSphinx::Configuration.instance.
    settings['index_options'] || {}
  defaults.symbolize_keys!

  @reference, @options, @block = reference, defaults.merge(options), block
end

Public Instance Methods

indices() click to toggle source
# File lib/thinking_sphinx/index.rb, line 20
def indices
  options[:delta] ? delta_indices : [single_index]
end

Private Instance Methods

delta_indices() click to toggle source
# File lib/thinking_sphinx/index.rb, line 43
def delta_indices
  [false, true].collect do |delta|
    index_class.new(
      reference,
      options.merge(:delta? => delta, :delta_processor => processor)
    ).tap do |index|
      index.definition_block = block
    end
  end
end
index_class() click to toggle source
# File lib/thinking_sphinx/index.rb, line 26
def index_class
  case options[:with]
  when :active_record
    ThinkingSphinx::ActiveRecord::Index
  when :real_time
    ThinkingSphinx::RealTime::Index
  else
    raise "Unknown index type: #{options[:with]}"
  end
end
processor() click to toggle source
# File lib/thinking_sphinx/index.rb, line 54
def processor
  @processor ||= ThinkingSphinx::Deltas.processor_for options.delete(:delta)
end
single_index() click to toggle source
# File lib/thinking_sphinx/index.rb, line 37
def single_index
  index_class.new(reference, options).tap do |index|
    index.definition_block = block
  end
end