Sha256: d4edb70ad05d6cb8a32adbb527ef9acbd09b5226684ca71e0714914ff5f3ac44

Contents?: true

Size: 902 Bytes

Versions: 1

Compression:

Stored size: 902 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 :id,          :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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thinking-sphinx-4.0.0 lib/thinking_sphinx/real_time/index/template.rb