<commit_before># encoding: utf-8
# An Update is a particular status message sent by one of our users.

class Update
  require 'cgi'
  include MongoMapper::Document

  if ENV['BONSAI_INDEX_URL'] || ENV['ELASTICSEARCH_INDEX_URL']
    include Tire::Model::Search
    include Tire::Model::Callbacks
    index_name ELASTICSEARCH_INDEX_NAME
  else
    # Fallback if elasticsearch is not enabled
    def self.search(query, params = {})
      leading_char = '\b'
      if query[0] == '#'
        leading_char = ''
      end
      self.where(:text => /#{leading_char}#{Regexp.quote(query)}\b/i).
           paginate(
             :page => params[:page],
             :per_page => params[:per_page],
             :order => :created_at.desc
          )
    end
  end
<commit_msg>When running tests, force elasticsearch to refresh after each update save<commit_after># encoding: utf-8
# An Update is a particular status message sent by one of our users.

class Update
  require 'cgi'
  include MongoMapper::Document

  if ENV['BONSAI_INDEX_URL'] || ENV['ELASTICSEARCH_INDEX_URL']
    include Tire::Model::Search
    include Tire::Model::Callbacks
    index_name ELASTICSEARCH_INDEX_NAME

    # This makes the document searchable immediately, which is nice when
    # you're running fast automated tests.
    after_save lambda { tire.index.refresh } if Rails.env.test?
  else
    # Fallback if elasticsearch is not enabled
    def self.search(query, params = {})
      leading_char = '\b'
      if query[0] == '#'
        leading_char = ''
      end
      self.where(:text => /#{leading_char}#{Regexp.quote(query)}\b/i).
           paginate(
             :page => params[:page],
             :per_page => params[:per_page],
             :order => :created_at.desc
          )
    end
  end

{'fraction_non_alphanumeric': 0.1108610016882386, 'fraction_numerical': 0.0022509848058525606, 'mean_word_length': 2.7274633123689727, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2055688', 'n_tokens_mistral': 543, 'n_tokens_neox': 539, 'n_words': 146}