<commit_before>class CorporateInformationPage < Edition
  include ::Attachable
  include Searchable

  has_one :edition_organisation, foreign_key: :edition_id, dependent: :destroy
  has_one :organisation, include: :translations, through: :edition_organisation, autosave: false
  has_one :edition_worldwide_organisation, foreign_key: :edition_id, dependent: :destroy
  has_one :worldwide_organisation, through: :edition_worldwide_organisation, autosave: false

  delegate :slug, :display_type_key, to: :corporate_information_page_type

  add_trait do
    def process_associations_before_save(new_edition)
      if @edition.organisation
        new_edition.organisation = @edition.organisation
      elsif @edition.worldwide_organisation
        new_edition.worldwide_organisation = @edition.worldwide_organisation
      end
    end
  end
  delegate :alternative_format_contact_email, :acronym, to: :owning_organisation

  validates :corporate_information_page_type_id, presence: true
  validate :only_one_organisation_or_worldwide_organisation

  before_save :ensure_title_is_blank
  def ensure_title_is_blank
    self.title = ''
  end

  def search_title
    title_prefix_organisation_name
  end

  def self.search_only
    # Ensure only CIPs associated with a live Organisation are indexed in search.<commit_msg>Index CIPs against their organisation in search.<commit_after>class CorporateInformationPage < Edition
  include ::Attachable
  include Searchable

  has_one :edition_organisation, foreign_key: :edition_id, dependent: :destroy
  has_one :organisation, include: :translations, through: :edition_organisation, autosave: false
  has_one :edition_worldwide_organisation, foreign_key: :edition_id, dependent: :destroy
  has_one :worldwide_organisation, through: :edition_worldwide_organisation, autosave: false

  delegate :slug, :display_type_key, to: :corporate_information_page_type

  add_trait do
    def process_associations_before_save(new_edition)
      if @edition.organisation
        new_edition.organisation = @edition.organisation
      elsif @edition.worldwide_organisation
        new_edition.worldwide_organisation = @edition.worldwide_organisation
      end
    end
  end
  delegate :alternative_format_contact_email, :acronym, to: :owning_organisation

  validates :corporate_information_page_type_id, presence: true
  validate :only_one_organisation_or_worldwide_organisation

  before_save :ensure_title_is_blank
  def ensure_title_is_blank
    self.title = ''
  end

  def search_title
    title_prefix_organisation_name
  end

  def search_index
    super.merge("organisations" => [owning_organisation.slug] )
  end

  def self.search_only
    # Ensure only CIPs associated with a live Organisation are indexed in search.
{'fraction_non_alphanumeric': 0.05707015630679753, 'fraction_numerical': 0.0, 'mean_word_length': 5.490566037735849, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '1676004', 'n_tokens_mistral': 855, 'n_tokens_neox': 835, 'n_words': 186}