<commit_before>class ThinkingSphinx::ActiveRecord::SQLSource::Template
  attr_reader :source

  def initialize(source)
    @source = source
  end

  def apply
    add_field class_column, :sphinx_internal_class, :facet => true

    add_attribute :id, :sphinx_internal_id, nil
    add_attribute '0', :sphinx_deleted,     :integer
  end

  private

  def add_attribute(column, name, type, options = {})
    source.attributes << ThinkingSphinx::ActiveRecord::Attribute.new(
      source.model, ThinkingSphinx::ActiveRecord::Column.new(column),
      options.merge(:as => name, :type => type)
    )
  end

  def add_field(column, name, options = {})
    source.fields << ThinkingSphinx::ActiveRecord::Field.new(
      source.model, ThinkingSphinx::ActiveRecord::Column.new(column),
      options.merge(:as => name)
    )
  end

  def class_column
    if inheriting?
      source.adapter.convert_nulls model.inheritance_column, "'#{model.name}'"
    else
      "'#{model.name}'"
    end
  end

  def inheriting?
    model.column_names.include?(model.inheritance_column)
  end

  def model
    source.model
  end
end<commit_msg>Correctly escape the null in the internal class column<commit_after>class ThinkingSphinx::ActiveRecord::SQLSource::Template
  attr_reader :source

  def initialize(source)
    @source = source
  end

  def apply
    add_field class_column, :sphinx_internal_class, :facet => true

    add_attribute :id, :sphinx_internal_id, nil
    add_attribute '0', :sphinx_deleted,     :integer
  end

  private

  def add_attribute(column, name, type, options = {})
    source.attributes << ThinkingSphinx::ActiveRecord::Attribute.new(
      source.model, ThinkingSphinx::ActiveRecord::Column.new(column),
      options.merge(:as => name, :type => type)
    )
  end

  def add_field(column, name, options = {})
    source.fields << ThinkingSphinx::ActiveRecord::Field.new(
      source.model, ThinkingSphinx::ActiveRecord::Column.new(column),
      options.merge(:as => name)
    )
  end

  def class_column
    if inheriting?
      adapter = source.adapter
      quoted_column = "#{adapter.quoted_table_name}.#{adapter.quote(model.inheritance_column)}"
      source.adapter.convert_nulls quoted_column, "'#{model.sti_name}'"
    else
      "'#{model.name}'"
    end
  end

  def inheriting?
    model.column_names.include?(model.inheritance_column)
  end

  def model
    source.model
  end
end
{'fraction_non_alphanumeric': 0.11485642946317104, 'fraction_numerical': 0.0008322929671244278, 'mean_word_length': 3.7984031936127742, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1083914', 'n_tokens_mistral': 776, 'n_tokens_neox': 759, 'n_words': 153}