Sha256: 3f54cc062899610a19b2b367fb210f5e0661f87589bf0387d7ebac0362b75cb5

Contents?: true

Size: 956 Bytes

Versions: 9

Compression:

Stored size: 956 Bytes

Contents

# frozen_string_literal: true

class ThinkingSphinx::RealTime::Index::Template
  attr_reader :index

  def initialize(index)
    @index = index
  end

  def apply
    add_field class_column, :sphinx_internal_class_name

    add_attribute primary_key,  :sphinx_internal_id,    :bigint
    add_attribute class_column, :sphinx_internal_class, :string, :facet => true
    add_attribute 0,            :sphinx_deleted,        :integer
  end

  private

  def add_attribute(column, name, type, options = {})
    index.add_attribute ThinkingSphinx::RealTime::Attribute.new(
      ThinkingSphinx::ActiveRecord::Column.new(*column),
      options.merge(:as => name, :type => type)
    )
  end

  def add_field(column, name)
    index.add_field ThinkingSphinx::RealTime::Field.new(
      ThinkingSphinx::ActiveRecord::Column.new(*column), :as => name
    )
  end

  def class_column
    [:class, :name]
  end

  def primary_key
    index.primary_key.to_sym
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
thinking-sphinx-5.1.0 lib/thinking_sphinx/real_time/index/template.rb
thinking-sphinx-5.0.0 lib/thinking_sphinx/real_time/index/template.rb
thinking-sphinx-4.4.1 lib/thinking_sphinx/real_time/index/template.rb
thinking-sphinx-4.4.0 lib/thinking_sphinx/real_time/index/template.rb
thinking-sphinx-4.3.2 lib/thinking_sphinx/real_time/index/template.rb
thinking-sphinx-4.3.1 lib/thinking_sphinx/real_time/index/template.rb
thinking-sphinx-4.3.0 lib/thinking_sphinx/real_time/index/template.rb
thinking-sphinx-4.2.0 lib/thinking_sphinx/real_time/index/template.rb
thinking-sphinx-4.1.0 lib/thinking_sphinx/real_time/index/template.rb