Sha256: ad54023501db0f51d98e887c25b5c60dd141134984fcf1465192db20981dd5ff

Contents?: true

Size: 1.39 KB

Versions: 17

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

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 attributes
    sources.collect(&:attributes).flatten
  end

  def delta?
    @options[:delta?]
  end

  def delta_processor
    @options[:delta_processor].try(:new, adapter, @options[:delta_options] || {})
  end

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

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

  def sources
    interpret_definition!
    super
  end

  def unique_attribute_names
    attributes.collect(&:name)
  end

  private

  def adapter
    @adapter ||= ThinkingSphinx::ActiveRecord::DatabaseAdapters.
      adapter_for(model)
  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],
      :delta_options   => @options[:delta_options],
      :primary_key     => primary_key
    }
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
thinking-sphinx-5.6.0 lib/thinking_sphinx/active_record/index.rb
thinking-sphinx-5.5.1 lib/thinking_sphinx/active_record/index.rb
thinking-sphinx-5.5.0 lib/thinking_sphinx/active_record/index.rb
thinking-sphinx-5.4.0 lib/thinking_sphinx/active_record/index.rb
thinking-sphinx-5.3.0 lib/thinking_sphinx/active_record/index.rb
thinking-sphinx-5.2.1 lib/thinking_sphinx/active_record/index.rb
thinking-sphinx-5.2.0 lib/thinking_sphinx/active_record/index.rb
thinking-sphinx-5.1.0 lib/thinking_sphinx/active_record/index.rb
thinking-sphinx-5.0.0 lib/thinking_sphinx/active_record/index.rb
thinking-sphinx-4.4.1 lib/thinking_sphinx/active_record/index.rb
thinking-sphinx-4.4.0 lib/thinking_sphinx/active_record/index.rb
thinking-sphinx-4.3.2 lib/thinking_sphinx/active_record/index.rb
thinking-sphinx-4.3.1 lib/thinking_sphinx/active_record/index.rb
thinking-sphinx-4.3.0 lib/thinking_sphinx/active_record/index.rb
thinking-sphinx-4.2.0 lib/thinking_sphinx/active_record/index.rb
thinking-sphinx-4.1.0 lib/thinking_sphinx/active_record/index.rb
thinking-sphinx-4.0.0 lib/thinking_sphinx/active_record/index.rb