<commit_before>DomElements = {
  matchingTerm: 'table.matching-term'
};

function clearAndHideResultTable() {
  var header = $('table.matching-term .header');
  $(DomElements.matchingTerm).html(header);
  $(DomElements.matchingTerm).hide();
}

function hideNoResults() {
  $('.no-results').hide();
}

function showNoResults() {
  $('.no-results').show();
}

function showResultTable() {
  hideNoResults();
  $(DomElements.matchingTerm).show();
}

function searchResults(query) {
  clearAndHideResultTable();
  return $('[data-search*=' + query).parent('tr');
}

function addToResultTable(result, searchTerm){
  showResultTable();
  var table = $('.matching-term');
  var lastChild = table.find('tr:last');

  $.each(result.children(), function(index, element) {
    var existing = $(element).html();
    var bolded = existing.replace(new RegExp("(" + searchTerm + ")", "i"), "<span class='highlighted'>$1</span>");
    $(element).html(bolded)
  });

  if(lastChild.length == 0) {
    table.html(result);
  }
  else {
    lastChild.after(result);
  }
}

$(document).on('ready', function(){
  $('input[name=search]').keyup(function(event){
    var searchTerm = event.target.value;
    if(searchTerm.length > 0) {
      hideNoResults();
      var results = searchResults(searchTerm.toLowerCase());
      if (results.length > 0) {
        $.each(results, function(index, value){
          addToResultTable($(value).clone(), searchTerm);
        });<commit_msg>Extract highlighting to a method<commit_after>DomElements = {
  matchingTerm: 'table.matching-term'
};

function clearAndHideResultTable() {
  var header = $('table.matching-term .header');
  $(DomElements.matchingTerm).html(header);
  $(DomElements.matchingTerm).hide();
}

function hideNoResults() {
  $('.no-results').hide();
}

function showNoResults() {
  $('.no-results').show();
}

function showResultTable() {
  hideNoResults();
  $(DomElements.matchingTerm).show();
}

function searchResults(query) {
  clearAndHideResultTable();
  return $('[data-search*=' + query).parent('tr');
}

function addToResultTable(result, searchTerm){
  showResultTable();
  var table = $('.matching-term');
  var lastChild = table.find('tr:last');

  $.each(result.children(), function(index, element) {
    highlight(element, term);
  });

  if(lastChild.length == 0) {
    table.html(result);
  }
  else {
    lastChild.after(result);
  }
}

function highlight(element, term) {
  var existing = $(element).html();
  var bolded = existing.replace(new RegExp("(" + searchTerm + ")", "i"), "<span class='highlighted'>$1</span>");
  $(element).html(bolded)
}

$(document).on('ready', function(){
  $('input[name=search]').keyup(function(event){
    var searchTerm = event.target.value;
    if(searchTerm.length > 0) {
      hideNoResults();
      var results = searchResults(searchTerm.toLowerCase());
      if (results.length > 0) {
        $.each(results, function(index, value){
          addToResultTable($(value).clone(), searchTerm);
        });
{'fraction_non_alphanumeric': 0.18937875751503006, 'fraction_numerical': 0.0026720106880427524, 'mean_word_length': 4.35778175313059, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1777856', 'n_tokens_mistral': 962, 'n_tokens_neox': 935, 'n_words': 163}