<commit_before>jQuery(document).ready(function() {

    $.extend( $.ui.autocomplete.prototype, {

    	_renderItem: function( ul, item) {
        return $( "<li></li>" )
          .data( "item.autocomplete", item )
          .append( $( "<a></a>" ).html( item.html || item.label ) )
          .appendTo( ul );
      }
    });
    

    //hide instructions
     $('#search_hint').hide();  
     
    //search hint
    $('#main_autocomplete').blur(
      function(){
        $('#main_autocomplete').val("I'm looking for...");
        $('#search_hint').hide();        
      }
    );

    $('#main_autocomplete').focus(
      function(){
        $('#main_autocomplete').val("");
        $('#search_hint').show();
      }
    );

    $("#main_autocomplete").autocomplete({
        delay: 0,
        source: function( request, response ) {
          $.ajax({
            url: "/search/autocomplete",
            dataType: "jsonp",
            data: {
              term: request.term
            },
            success: function( data ) {
              var highlight_term = function(string,term) {
                html_safe = html_escape(string);
                var terms = term.split(' ');
                for (var i in terms)  {
                  var clean_term = html_escape(terms[i].replace(/^\s+|\s+$/g, ''));
                  if (clean_term != "") {
                    var regex = new RegExp("("+clean_term+")","ig");
                    html_safe = html_safe.replace(regex,'<em>$1</em>');
                  }
                }
                return html_safe;
              };
              var filter = function(search_term,data) {
                return $.map(data, function(item) {
                  return {
                    label: html_escape(item.label),
                    html:  highlight_term(item.label,search_term),
                    url:   item.url + "?q=" + encodeURIComponent(item.label)
                  }
                });
              };
              var html_escape = function( string) {
                return $('<div/>').text(string).html();
              }
              var search_term = request.term;
						  last_item = {
                label: "search the site for "+html_escape(search_term),
                html:  "search the site for <em>"+html_escape(search_term)+"</em>",
                url:   "/search?q="+encodeURIComponent(search_term)
              };
              data = filter(search_term,data.slice(0,10));
              data.push(last_item);
              response( data );       
            }
          });
        },
        select: function(event, ui) {
          location.href = ui.item.url
        },
        open: function(event, ui){
          // console.debug(event);<commit_msg>Show search immediately to make search seem more responsive<commit_after>jQuery(document).ready(function() {

    $.extend( $.ui.autocomplete.prototype, {

    	_renderItem: function( ul, item) {
        return $( "<li></li>" )
          .data( "item.autocomplete", item )
          .append( $( "<a></a>" ).html( item.html || item.label ) )
          .appendTo( ul );
      }
    });
    

    //hide instructions
     $('#search_hint').hide();  
     
    //search hint
    $('#main_autocomplete').blur(
      function(){
        $('#main_autocomplete').val("I'm looking for...");
        $('#search_hint').hide();        
      }
    );

    $('#main_autocomplete').focus(
      function(){
        $('#main_autocomplete').val("");
        $('#search_hint').show();
      }
    );

    $("#main_autocomplete").autocomplete({
        delay: 0,
        source: function( request, response ) {
          var html_escape = function( string) {
                return $('<div/>').text(string).html();
          };
          
          var search_site = function(search_term) {
            return {
                label: "search the site for "+html_escape(search_term),
                html:  "search the site for <em>"+html_escape(search_term)+"</em>",
                url:   "/search?q="+encodeURIComponent(search_term)
              };
          };
          
          var loading = function() {
            var data = [];
            data.push(search_site(request.term));
            response(data);
          };

          var ajax = function() {
            $.ajax({
              url: "/search/autocomplete",
              dataType: "jsonp",
              data: { term: request.term },
              success: function( data ) {
                var highlight_term = function(string,term) {
                  html_safe = html_escape(string);
                  var terms = term.split(' ');
                  for (var i in terms)  {
                    var clean_term = html_escape(terms[i].replace(/^\s+|\s+$/g, ''));
                    if (clean_term != "") {
                      var regex = new RegExp("("+clean_term+")","ig");
                      html_safe = html_safe.replace(regex,'<em>$1</em>');
                    }
                  }
                  return html_safe;
                };
                var filter = function(search_term,data) {
                  return $.map(data, function(item) {
                    return {
                      label: html_escape(item.label),
                      html:  highlight_term(item.label,search_term),
                      url:   item.url + "?q=" + encodeURIComponent(item.label)
                    }
                  });
                };
                var search_term = request.term;
                data = filter(search_term,data.slice(0,10));
                data.push(search_site(search_term));
                response( data );       
              }
            });
          };

          term = request.term;
          if (term.length == 0) {
            response([]);
          } else if (term.length == 1) {
            loading();
          } else {
            ajax();
          }

        },
        select: function(event, ui) {
          location.href = ui.item.url
        },
        open: function(event, ui){
          // console.debug(event);
{'fraction_non_alphanumeric': 0.14969567363053135, 'fraction_numerical': 0.001974008883039974, 'mean_word_length': 1.3529411764705883, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '2105054', 'n_tokens_mistral': 1682, 'n_tokens_neox': 1601, 'n_words': 295}