<commit_before>$(".search-box").focus();

var reverseIndex = Object.create(null);

function createReverseIndex() {
  videoCaptions.forEach(function (captions, i) {
    var currentTime = 0;
    captions.forEach(function (caption, j) {
      var prevCaptionSnippet = (captions[j-1] && captions[j-1].text) || "";
      var nextCaptionSnippet = (captions[j+1] && captions[j+1].text) || "";

      var previousSnippetTime = prevCaptionSnippet.length
                              ? currentTime - (captions[j-1].width / 64) - (2/64)
                              : currentTime
                              ;

      caption.text.split(/\s+/).forEach(function (word) {
        word = word.replace(/[.,!"?()]/g,"").toLowerCase();
        if (word) {
          reverseIndex[word] = (reverseIndex[word] || []);
          reverseIndex[word].push({
            videoIndex: i,
            startTime: previousSnippetTime,
            snippet: caption.text,
            prevSnippet: prevCaptionSnippet,
            nextSnippet: nextCaptionSnippet
          });
        }
      });
      currentTime += (caption.width / 64) + (2/64);
    });
  });
}

$(document).ready(function () {
  createReverseIndex();
  bindEventListeners();
  $(".search-box").keyup();
});

/*
  Binds event listeners on input elements
*/
function bindEventListeners() {
  var debouncedInputKeypress = debounce(inputKeypress, 200);
  var debouncedSendGAEvent = debounce(sendGAEvent, 1000);
  $(".search-box").off().keyup(debouncedInputKeypress)
                        .keyup(debouncedSendGAEvent);
  $(".search-box").keyup(); // Trigger event to account for auto fill
}

/*
  Helper debounce function
*/
function debounce (func, wait, immediate) {
  var timeout;
  return function() {
    var context = this, args = arguments;
    var later = function() {
      timeout = null;
      if (!immediate) func.apply(context, args);
    };
    var callNow = immediate && !timeout;
    clearTimeout(timeout);
    timeout = setTimeout(later, wait);
    if (callNow) func.apply(context, args);
  };
}

/*
  Helper throttle function
*/
function throttle (cb, limit) {
  var wait = false;
  return function () {
    if (!wait) {
      cb.call();
      wait = true;
      setTimeout(function () {
        wait = false;
      }, limit);
    }
  };
}

/*
  Send a search event to GA
*/
function sendGAEvent() {
  var searchQuery = $(".search-box").val();
  if (searchQuery.length) {
    ga('send', 'event', 'homepage', 'search', searchQuery);
  }
}

/*
  Generate all combinations of a words array
*/
function getCombinations(words) {
  var result = [];
  var f = function(prefix, words) {
    for (var i = 0; i < words.length; i++) {
      result.push(prefix.concat(words[i]));
      f(prefix.concat(words[i]), words.slice(i + 1));
    }
  };
  f([], words);
  return result;
}

/*
  Captures the input keypresses and reacts accordingly
*/
function inputKeypress(e) {
  $(".search-results-container").empty();
  var results = Object.create(null);
  var query = $(".search-box").val().toLowerCase();
  query = query.trim().replace(/[.,!"?()]/g,"").split(/\s+/);

  var subQueries = getCombinations(query);

  subQueries = subQueries.sort(function (a,b) {
    return b.length - a.length;
  });

  subQueries.forEach(function (subQuery) {
    var query = subQuery;
    var firstQueryResults = reverseIndex[query[0]] || [];
    firstQueryResults = firstQueryResults.filter(function (result) {<commit_msg>Update search to split by dashes<commit_after>$(".search-box").focus();

var reverseIndex = Object.create(null);

function createReverseIndex() {
  videoCaptions.forEach(function (captions, i) {
    var currentTime = 0;
    captions.forEach(function (caption, j) {
      var prevCaptionSnippet = (captions[j-1] && captions[j-1].text) || "";
      var nextCaptionSnippet = (captions[j+1] && captions[j+1].text) || "";

      var previousSnippetTime = prevCaptionSnippet.length
                              ? currentTime - (captions[j-1].width / 64) - (2/64)
                              : currentTime
                              ;

      caption.text.replace(/-/g, " ").split(/\s+/).forEach(function (word) {
        word = word.replace(/[.,!"?()]/g,"").toLowerCase();
        if (word) {
          reverseIndex[word] = (reverseIndex[word] || []);
          reverseIndex[word].push({
            videoIndex: i,
            startTime: previousSnippetTime,
            snippet: caption.text,
            prevSnippet: prevCaptionSnippet,
            nextSnippet: nextCaptionSnippet
          });
        }
      });
      currentTime += (caption.width / 64) + (2/64);
    });
  });
}

$(document).ready(function () {
  createReverseIndex();
  bindEventListeners();
  $(".search-box").keyup();
});

/*
  Binds event listeners on input elements
*/
function bindEventListeners() {
  var debouncedInputKeypress = debounce(inputKeypress, 200);
  var debouncedSendGAEvent = debounce(sendGAEvent, 1000);
  $(".search-box").off().keyup(debouncedInputKeypress)
                        .keyup(debouncedSendGAEvent);
  $(".search-box").keyup(); // Trigger event to account for auto fill
}

/*
  Helper debounce function
*/
function debounce (func, wait, immediate) {
  var timeout;
  return function() {
    var context = this, args = arguments;
    var later = function() {
      timeout = null;
      if (!immediate) func.apply(context, args);
    };
    var callNow = immediate && !timeout;
    clearTimeout(timeout);
    timeout = setTimeout(later, wait);
    if (callNow) func.apply(context, args);
  };
}

/*
  Helper throttle function
*/
function throttle (cb, limit) {
  var wait = false;
  return function () {
    if (!wait) {
      cb.call();
      wait = true;
      setTimeout(function () {
        wait = false;
      }, limit);
    }
  };
}

/*
  Send a search event to GA
*/
function sendGAEvent() {
  var searchQuery = $(".search-box").val();
  if (searchQuery.length) {
    ga('send', 'event', 'homepage', 'search', searchQuery);
  }
}

/*
  Generate all combinations of a words array
*/
function getCombinations(words) {
  var result = [];
  var f = function(prefix, words) {
    for (var i = 0; i < words.length; i++) {
      result.push(prefix.concat(words[i]));
      f(prefix.concat(words[i]), words.slice(i + 1));
    }
  };
  f([], words);
  return result;
}

/*
  Captures the input keypresses and reacts accordingly
*/
function inputKeypress(e) {
  $(".search-results-container").empty();
  var results = Object.create(null);
  var query = $(".search-box").val().toLowerCase();
  query = query.trim().replace(/[.,!"?()]/g,"").replace(/-/g, " ").split(/\s+/);

  var subQueries = getCombinations(query);

  subQueries = subQueries.sort(function (a,b) {
    return b.length - a.length;
  });

  subQueries.forEach(function (subQuery) {
    var query = subQuery;
    var firstQueryResults = reverseIndex[query[0]] || [];
    firstQueryResults = firstQueryResults.filter(function (result) {
{'fraction_non_alphanumeric': 0.1620843529581114, 'fraction_numerical': 0.0074852454296818775, 'mean_word_length': 2.735483870967742, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4871374', 'n_tokens_mistral': 2229, 'n_tokens_neox': 2154, 'n_words': 465}