<commit_before>class Proposal < ActiveRecord::Base
  include Flaggable
  include Taggable
  include Conflictable
  include Measurable
  include Sanitizable
  include PgSearch
  include SearchCache

  apply_simple_captcha
  acts_as_votable
  acts_as_paranoid column: :hidden_at
  include ActsAsParanoidAliases

  belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
  has_many :comments, as: :commentable

  validates :title, presence: true
  validates :question, presence: true
  validates :summary, presence: true
  validates :author, presence: true
  validates :responsible_name, presence: true

  validates :title, length: { in: 4..Proposal.title_max_length }
  validates :description, length: { maximum: Proposal.description_max_length }
  validates :question, length: { in: 10..Proposal.question_max_length }
  validates :responsible_name, length: { in: 6..Proposal.responsible_name_max_length }

  validates :terms_of_service, acceptance: { allow_nil: false }, on: :create

  before_validation :set_responsible_name

  before_save :calculate_hot_score, :calculate_confidence_score

  scope :for_render, -> { includes(:tags) }
  scope :sort_by_hot_score , -> { order(hot_score: :desc) }
  scope :sort_by_confidence_score , -> { order(confidence_score: :desc) }
  scope :sort_by_created_at, -> { order(created_at: :desc) }
  scope :sort_by_most_commented, -> { order(comments_count: :desc) }
  scope :sort_by_random, -> { order("RANDOM()") }
  scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }

  pg_search_scope :pg_search, {
    against: {
      title:       'A',
      question:    'B',
      summary:     'C',
      description: 'D'
    },
    associated_against: {
      tags: :name
    },
    using: {
      tsearch: { dictionary: "spanish", tsvector_column: 'tsv' },
      trigram: { threshold: 0.1 },
    },
    ranked_by: '(:tsearch + proposals.cached_votes_up)',
    order_within_rank: "proposals.created_at DESC"
  }

  def searchable_values
    values = {
      title => 'A',
      question => 'B',
      summary => 'C',<commit_msg>adds consistent indentation to hash<commit_after>class Proposal < ActiveRecord::Base
  include Flaggable
  include Taggable
  include Conflictable
  include Measurable
  include Sanitizable
  include PgSearch
  include SearchCache

  apply_simple_captcha
  acts_as_votable
  acts_as_paranoid column: :hidden_at
  include ActsAsParanoidAliases

  belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
  has_many :comments, as: :commentable

  validates :title, presence: true
  validates :question, presence: true
  validates :summary, presence: true
  validates :author, presence: true
  validates :responsible_name, presence: true

  validates :title, length: { in: 4..Proposal.title_max_length }
  validates :description, length: { maximum: Proposal.description_max_length }
  validates :question, length: { in: 10..Proposal.question_max_length }
  validates :responsible_name, length: { in: 6..Proposal.responsible_name_max_length }

  validates :terms_of_service, acceptance: { allow_nil: false }, on: :create

  before_validation :set_responsible_name

  before_save :calculate_hot_score, :calculate_confidence_score

  scope :for_render, -> { includes(:tags) }
  scope :sort_by_hot_score , -> { order(hot_score: :desc) }
  scope :sort_by_confidence_score , -> { order(confidence_score: :desc) }
  scope :sort_by_created_at, -> { order(created_at: :desc) }
  scope :sort_by_most_commented, -> { order(comments_count: :desc) }
  scope :sort_by_random, -> { order("RANDOM()") }
  scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }

  pg_search_scope :pg_search, {
    against: {
      title:       'A',
      question:    'B',
      summary:     'C',
      description: 'D'
    },
    associated_against: {
      tags: :name
    },
    using: {
      tsearch: { dictionary: "spanish", tsvector_column: 'tsv' },
      trigram: { threshold: 0.1 },
    },
    ranked_by: '(:tsearch + proposals.cached_votes_up)',
    order_within_rank: "proposals.created_at DESC"
  }

  def searchable_values
    values = {
      title       => 'A',
      question    => 'B',
      summary     => 'C',
{'fraction_non_alphanumeric': 0.11407023332547726, 'fraction_numerical': 0.0028281876031110063, 'mean_word_length': 3.9812206572769955, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '1320160', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1391, 'n_words': 309}