<commit_before>module SearchHelper
  def highlight_text(text, details, field)
    return text if details.nil?
    return text if details[:highlight].nil?
    highlighted_text = details[:highlight][field]
    return text if highlighted_text.nil?
    to_replace = highlighted_text.gsub('<mark>', '').gsub('</mark>', '')

    return text.gsub(to_replace, highlighted_text)
  end

  def highlight_code(text, detail, locale)
    text_field = ('text_' + locale.to_s + '.word_middle').to_sym
    return highlight_text(text, detail, text_field) unless detail.nil? || detail[:highlight].nil? || detail[:highlight][text_field].nil?

    # let's try to highlight a relevant code
    return text if detail.nil?
    return text if detail[:highlight].nil?
    highlighted_text = detail[:highlight][('relevant_codes_' + locale.to_s).to_sym]
    return text if highlighted_text.nil?
    relevant_codes = highlighted_text.split("\n")
    first = ''
    i = 0
    while first.blank?
      first = relevant_codes[i] if relevant_codes[i].include? '<mark>'
      i += 1
    end
    first += '</mark>' unless first.include? '</mark>'
    return text + '<div class="small">(' + I18n.t('relevant_code') + ': ' + first + ')</div>'
  end
end<commit_msg>Do not show anything if relevant codes are not highlighted.<commit_after>module SearchHelper
  def highlight_text(text, details, field)
    return text if details.nil?
    return text if details[:highlight].nil?
    highlighted_text = details[:highlight][field]
    return text if highlighted_text.nil?
    to_replace = highlighted_text.gsub('<mark>', '').gsub('</mark>', '')

    return text.gsub(to_replace, highlighted_text)
  end

  def highlight_code(text, detail, locale)
    text_field = ('text_' + locale.to_s + '.word_middle').to_sym
    return highlight_text(text, detail, text_field) unless detail.nil? || detail[:highlight].nil? || detail[:highlight][text_field].nil?

    # let's try to highlight a relevant code
    return text if detail.nil?
    return text if detail[:highlight].nil?
    highlighted_text = detail[:highlight][('relevant_codes_' + locale.to_s).to_sym]
    return text if highlighted_text.nil?
    relevant_codes = highlighted_text.split("\n")
    first = ''
    i = 0
    while first.blank? && relevant_codes.length > i
      first = relevant_codes[i] if relevant_codes[i].include? '<mark>'
      i += 1
    end
    return text if first.blank?
    first += '</mark>' unless first.include? '</mark>'
    return text + '<div class="small">(' + I18n.t('relevant_code') + ': ' + first + ')</div>'
  end
end
{'fraction_non_alphanumeric': 0.14096056228035925, 'fraction_numerical': 0.0031237797735259665, 'mean_word_length': 3.9174664107485606, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, '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': '5741001', 'n_tokens_mistral': 797, 'n_tokens_neox': 772, 'n_words': 202}