Sha256: ecdd0df1c86f5dfe145133f01ab9ad5d5e952a6880f10d71d64a16403bd9f993

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

class ThinkingSphinx::ActiveRecord::Index < Riddle::Configuration::Index
  include ThinkingSphinx::Core::Index

  attr_reader :reference
  attr_writer :definition_block

  def append_source
    ThinkingSphinx::ActiveRecord::SQLSource.new(
      model, source_options.merge(:position => sources.length)
    ).tap do |source|
      sources << source
    end
  end

  def delta?
    @options[:delta?]
  end

  def delta_processor
    @options[:delta_processor].try(:new, adapter)
  end

  def facets
    @facets ||= sources.collect(&:facets).flatten
  end

  def unique_attribute_names
    attributes.collect(&:name)
  end

  private

  def adapter
    @adapter ||= ThinkingSphinx::ActiveRecord::DatabaseAdapters.
      adapter_for(model)
  end

  def attributes
    sources.collect(&:attributes).flatten
  end

  def fields
    sources.collect(&:fields).flatten
  end

  def interpreter
    ThinkingSphinx::ActiveRecord::Interpreter
  end

  def name_suffix
    @options[:delta?] ? 'delta' : 'core'
  end

  def source_options
    {
      :name            => name,
      :offset          => offset,
      :delta?          => @options[:delta?],
      :delta_processor => @options[:delta_processor],
      :primary_key     => @options[:primary_key] || model.primary_key || :id
    }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thinking-sphinx-3.0.0.rc lib/thinking_sphinx/active_record/index.rb