<commit_before>class AdopterSearcher
  PER_PAGE = 30

  STATUSES = [
    'new',
    'pend response',
    'workup',
    'approved'
  ].freeze

  def initialize(params: {})
    @params = params
  end

  def search
    @adopters = Adopter

    if name_search?
      @adopters = @adopters.where('adopters.name ILIKE ?', "%#{@params[:search].strip}%")
    elsif active_status_search?
      @adopters = @adopters.where('status IN (?)', STATUSES)
    elsif status_search?
      @adopters = @adopters.where(status: @params[:status])
    end

    with_includes
    for_page(@params[:page])

    @adopters
  end

  def self.search(params: {})
    self.new(params: params).search
  end

  private

  def with_includes
    @adopters = @adopters.includes(:user, :comments, :dogs, :adoption_app)
  end

  def active_status_search?
    @params[:status] == 'active'
  end

  def status_search?
    @params.has_key? :status
  end

  def name_search?
    @params[:search].present?
  end

  def for_page(page = nil)
    @adopters = @adopters.paginate(per_page: PER_PAGE, page: page || 1)
  end
end<commit_msg>Adds sort for pagination ordering guarantee<commit_after>class AdopterSearcher
  PER_PAGE = 30

  STATUSES = [
    'new',
    'pend response',
    'workup',
    'approved'
  ].freeze

  def initialize(params: {})
    @params = params
  end

  def search
    @adopters = Adopter

    if name_search?
      @adopters = @adopters.where('adopters.name ILIKE ?', "%#{@params[:search].strip}%")
    elsif active_status_search?
      @adopters = @adopters.where('status IN (?)', STATUSES)
    elsif status_search?
      @adopters = @adopters.where(status: @params[:status])
    end

    with_includes
    with_sort
    for_page(@params[:page])

    @adopters
  end

  def self.search(params: {})
    self.new(params: params).search
  end

  private

  def with_includes
    @adopters = @adopters.includes(:user, :comments, :dogs, :adoption_app)
  end

  def active_status_search?
    @params[:status] == 'active'
  end

  def status_search?
    @params.has_key? :status
  end

  def name_search?
    @params[:search].present?
  end

  def with_sort
    @adopters = @adopters.order(id: :asc)
  end

  def for_page(page = nil)
    @adopters = @adopters.paginate(per_page: PER_PAGE, page: page || 1)
  end
end
{'fraction_non_alphanumeric': 0.12844036697247707, 'fraction_numerical': 0.002621231979030144, 'mean_word_length': 3.225092250922509, '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': '1439379', 'n_tokens_mistral': 852, 'n_tokens_neox': 792, 'n_words': 173}