<commit_before>class FootnoteSearchService
  attr_accessor :scope
  attr_reader :code, :description

  def initialize(attributes)
    self.scope = Footnote
      .actual
      .eager(:footnote_descriptions)
      .eager(:goods_nomenclatures)

    @code = attributes['code']
    @description = attributes['description']
  end

  def perform
    apply_code_filter if code.present?
    apply_description_filter if description.present?
    scope.all
  end

  private

  def apply_code_filter
    self.scope = scope
      .where("footnotes.footnote_type_id::text || footnotes.footnote_id::text LIKE '%#{code}%'")
  end

  def apply_description_filter
    self.scope = scope
      .join(:footnote_description_periods, [%i[footnotes__footnote_type_id footnote_description_periods__footnote_type_id], %i[footnotes__footnote_id footnote_description_periods__footnote_id]])
      .join(:footnote_descriptions, [%i[footnote_description_periods__footnote_description_period_sid footnote_descriptions__footnote_description_period_sid]])
      .with_actual(FootnoteDescriptionPeriod)
      .where(Sequel.ilike(:footnote_descriptions__description, "%#{description}%"))
  end
end<commit_msg>Match footnote code searches from the beginning of the string only<commit_after>class FootnoteSearchService
  attr_accessor :scope
  attr_reader :code, :description

  def initialize(attributes)
    self.scope = Footnote
      .actual
      .eager(:footnote_descriptions)
      .eager(:goods_nomenclatures)

    @code = attributes['code']
    @description = attributes['description']
  end

  def perform
    apply_code_filter if code.present?
    apply_description_filter if description.present?
    scope.all
  end

  private

  def apply_code_filter
    self.scope = scope
      .where("footnotes.footnote_type_id::text || footnotes.footnote_id::text LIKE '#{code}%'")
  end

  def apply_description_filter
    self.scope = scope
      .join(:footnote_description_periods, [%i[footnotes__footnote_type_id footnote_description_periods__footnote_type_id], %i[footnotes__footnote_id footnote_description_periods__footnote_id]])
      .join(:footnote_descriptions, [%i[footnote_description_periods__footnote_description_period_sid footnote_descriptions__footnote_description_period_sid]])
      .with_actual(FootnoteDescriptionPeriod)
      .where(Sequel.ilike(:footnote_descriptions__description, "%#{description}%"))
  end
end
{'fraction_non_alphanumeric': 0.08534554537885096, 'fraction_numerical': 0.0, 'mean_word_length': 5.274151436031332, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2874564', 'n_tokens_mistral': 711, 'n_tokens_neox': 713, 'n_words': 121}