<commit_before>class Search

  def self.search(query)
    unsing = Song.includes(:artist).where(:last_sang_at => nil)
    already = Song.includes(:artist).where.not(:last_sang_at => nil)

    unless query.blank?
      unsing = unsing.where(search_with_word(query))
      already = already.where(search_with_word(query))
    end

    all_songs = unsing.to_a + already.to_a
  end

  def self.search_with_word(query)
    q = "%#{query}%"
    [Song, Artist].map {|cond| cond.arel_table[:name].matches(q) }
                  .inject {|cond, i| cond.or i }
  end
end
<commit_msg>order by last_sang_at already sang<commit_after>class Search

  def self.search(query)
    unsing = Song.includes(:artist).where(:last_sang_at => nil)
    already = Song.includes(:artist).where.not(:last_sang_at => nil).reorder('last_sang_at ASC')

    unless query.blank?
      unsing = unsing.where(search_with_word(query))
      already = already.where(search_with_word(query))
    end

    all_songs = unsing.to_a + already.to_a
  end

  def self.search_with_word(query)
    q = "%#{query}%"
    [Song, Artist].map {|cond| cond.arel_table[:name].matches(q) }
                  .inject {|cond, i| cond.or i }
  end
end

{'fraction_non_alphanumeric': 0.13807531380753138, 'fraction_numerical': 0.0, 'mean_word_length': 3.349090909090909, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1637166', 'n_tokens_mistral': 436, 'n_tokens_neox': 422, 'n_words': 77}