<commit_before>class Story < ApplicationRecord
  def self.stories_filter(tags, limit = 5)
    tags_array = tags.split(',') if tags
    tagged_stories = tagged_stories(tags_array, limit)
    return tagged_stories if tagged_stories.length >= 5
    more_stories = not_tagged_by(tags_array, limit)
    return (tagged_stories + more_stories).first(5) if tagged_stories
    more_stories
  end

  def self.tagged_stories(tags, limit)
    Story.where('tags && ARRAY[?]::varchar[]', tags).
      order(published_at: :desc).
      limit(limit)
  end

  def self.not_tagged_by(tags, limit)
    Story.where('NOT tags && ARRAY[?]::varchar[] OR tags IS NULL', tags).
      order(published_at: :desc).
      limit(limit)
  end<commit_msg>Fixed  story.rb causing failing specs<commit_after>class Story < ApplicationRecord
  def self.stories_filter(tags, limit=5)
    tags_array = tags.split(',') if tags
    tagged_stories = tagged_stories(tags_array, limit)
    return tagged_stories if tagged_stories.length >= limit.to_i
    more_stories = not_tagged_by(tags_array, limit)
    return (tagged_stories + more_stories).first(limit.to_i) if tagged_stories
    more_stories
  end

  def self.tagged_stories(tags, limit)
    Story.where('tags && ARRAY[?]::varchar[]', tags).
      order(published_at: :desc).
      limit(limit)
  end

  def self.not_tagged_by(tags, limit)
    Story.where('NOT tags && ARRAY[?]::varchar[] OR tags IS NULL', tags).
      order(published_at: :desc).
      limit(limit)
  end
{'fraction_non_alphanumeric': 0.11911170928667564, 'fraction_numerical': 0.0026917900403768506, 'mean_word_length': 4.040677966101695, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6916545', 'n_tokens_mistral': 525, 'n_tokens_neox': 503, 'n_words': 110}