<commit_before>Search = {
  // Determines if the AJAX request received should be displayed
  shouldDisplayResults: function(r) {
    return (r.request.url == Search.lastQuerySent) &&
           $('content').hasClassName('search_results');
  },
  getResults: function(query, force) {
    // Go back to the previous pane if the query string is empty
    if(query.length == 0) {
      Search.lastQueryTyped = null;
      Search.lastQuerySent = null;
      Pane.retrieve();
      return;
    }
    // Don't auto-search for short strings, unless we force search (pressing Return)
    if(query.length < 3 && !force) { return; }

    // Save the last query, and don't re-search if it's the same one we just fetched
    if (Search.lastQueryTyped == query) { return; }
    Search.lastQueryTyped = query;

    // Perform an API call to fetch search results
    var url = "/api/1/search/?q="+escape(query);
    new Ajax.Request(url, {
      method: "get",
      onLoading: function(r) {
        // Save content pane if we are going to show the search pane
        if(!Search.lastQuerySent) { Pane.save(); }
        // Mark this query as the last search we asked for
        Search.lastQuerySent = r.request.url;
        // Display a placeholder for search
        Pane.replace(
          Mustache.to_html(Templates.search.loading, { query: query }),
          "/search/?q="+escape(query)
        );
        $('content').addClassName('search_results');
      },
      onComplete: function(r) {
        if(!Search.shouldDisplayResults(r)) { return; }
        $('content').down('.loading').remove();
      },
      onSuccess: function(r) {
        if(!Search.shouldDisplayResults(r)) { return; }
        response = JSON.parse(r.responseText);
        Search.displayResults(response);
      },
      onFailure: function(r) {
        if(!Search.shouldDisplayResults(r)) { return; }
        $('search_result').update('<p>An error occurred, please try reloading the page.</p>');
      }
    })
  },
  displayResults: function(response) {
    response.objects.each(function(r) {
      r.icon_class = Search.icons[r.type];
      r.project = response.references.detect(function(p) {
        return p.type == "Project" && p.id == r.project_id;
      });
      r.link = "/projects/"+r.project.permalink+"/"+r.type.underscore()+"s/"+r.id;
      r.timeago = Date.parseFormattedString(r.updated_at).timeAgo();
    });
    response.length = response.objects.length;
    $('search_results').update(<commit_msg>Truncate large names in search results to 65 characters<commit_after>Search = {
  // Determines if the AJAX request received should be displayed
  shouldDisplayResults: function(r) {
    return (r.request.url == Search.lastQuerySent) &&
           $('content').hasClassName('search_results');
  },
  getResults: function(query, force) {
    // Go back to the previous pane if the query string is empty
    if(query.length == 0) {
      Search.lastQueryTyped = null;
      Search.lastQuerySent = null;
      Pane.retrieve();
      return;
    }
    // Don't auto-search for short strings, unless we force search (pressing Return)
    if(query.length < 3 && !force) { return; }

    // Save the last query, and don't re-search if it's the same one we just fetched
    if (Search.lastQueryTyped == query) { return; }
    Search.lastQueryTyped = query;

    // Perform an API call to fetch search results
    var url = "/api/1/search/?q="+escape(query);
    new Ajax.Request(url, {
      method: "get",
      onLoading: function(r) {
        // Save content pane if we are going to show the search pane
        if(!Search.lastQuerySent) { Pane.save(); }
        // Mark this query as the last search we asked for
        Search.lastQuerySent = r.request.url;
        // Display a placeholder for search
        Pane.replace(
          Mustache.to_html(Templates.search.loading, { query: query }),
          "/search/?q="+escape(query)
        );
        $('content').addClassName('search_results');
      },
      onComplete: function(r) {
        if(!Search.shouldDisplayResults(r)) { return; }
        $('content').down('.loading').remove();
      },
      onSuccess: function(r) {
        if(!Search.shouldDisplayResults(r)) { return; }
        response = JSON.parse(r.responseText);
        Search.displayResults(response);
      },
      onFailure: function(r) {
        if(!Search.shouldDisplayResults(r)) { return; }
        $('search_result').update('<p>An error occurred, please try reloading the page.</p>');
      }
    })
  },
  displayResults: function(response) {
    response.objects.each(function(r) {
      r.icon_class = Search.icons[r.type];
      r.project = response.references.detect(function(p) {
        return p.type == "Project" && p.id == r.project_id;
      });
      r.link = "/projects/"+r.project.permalink+"/"+r.type.underscore()+"s/"+r.id;
      r.timeago = Date.parseFormattedString(r.updated_at).timeAgo();
      r.name = r.name.truncate(65);
    });
    response.length = response.objects.length;
    $('search_results').update(
{'fraction_non_alphanumeric': 0.14299880999603332, 'fraction_numerical': 0.0019833399444664813, 'mean_word_length': 2.689100219458669, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '4118208', 'n_tokens_mistral': 1522, 'n_tokens_neox': 1490, 'n_words': 353}