<commit_before>define([
  "underscore",
  "backbone",
  "providers/ddg/DDGCategoryProvider",
  "providers/Provider",
	"providers/ProviderEntry"
], function(
  _,
  Backbone,
  DDGCategoryProvider,
  Provider,
	ProviderEntry
) {

  var ACTIVATOR= "? ";
  var ADAPTER= function(filter) {
    return filter.substring(ACTIVATOR.length);
  };

  var directResults= function(response) {
    var results= _.filter(response, function(entry) {
      return entry.Text;
    });

    return _.map(results, function(result) {
      return new ProviderEntry({
        label: result.Text,
        url: result.FirstURL
      });
    });
  };

  var groupedResults= function(response) {
    var results= _.filter(response, function(entry) {
      return entry.Name;
    });

    return _.map(results, function(result) {
      return new DDGCategoryProvider({ label: result.Name }, result.Topics);
    });
  };

  return Provider.extend({

    debounced: function() {
      return true;
    },

    adapter: function() {
      return ADAPTER;
    },

    accepts: function(filter) {
      return filter.indexOf(ACTIVATOR) !== -1;
    },

    retrieve: function(filter) {
      filter= ADAPTER(filter);
      var result= $.Deferred();
      var ddgQuery= "http://api.duckduckgo.com/?q=" + filter + "&format=json";

      $.get(ddgQuery,function(j) {},'jsonp')
        .done(function(response) {
          response= response.RelatedTopics;
          var direct= directResults(response);
          var groups= groupedResults(response);

          result.resolve(new Backbone.Collection(direct.concat(groups)));
        });

      return result;
    }

  });
});<commit_msg>Do not query DDG with empty string<commit_after>define([
  "underscore",
  "backbone",
  "providers/ddg/DDGCategoryProvider",
  "providers/Provider",
	"providers/ProviderEntry"
], function(
  _,
  Backbone,
  DDGCategoryProvider,
  Provider,
	ProviderEntry
) {

  var ACTIVATOR= "? ";
  var ADAPTER= function(filter) {
    return filter.substring(ACTIVATOR.length);
  };

  var directResults= function(response) {
    var results= _.filter(response, function(entry) {
      return entry.Text;
    });

    return _.map(results, function(result) {
      return new ProviderEntry({
        label: result.Text,
        url: result.FirstURL
      });
    });
  };

  var groupedResults= function(response) {
    var results= _.filter(response, function(entry) {
      return entry.Name;
    });

    return _.map(results, function(result) {
      return new DDGCategoryProvider({ label: result.Name }, result.Topics);
    });
  };

  return Provider.extend({

    debounced: function() {
      return true;
    },

    adapter: function() {
      return ADAPTER;
    },

    accepts: function(filter) {
      return filter.indexOf(ACTIVATOR) !== -1 && this.adapter()(filter).trim().length > 0;
    },

    retrieve: function(filter) {
      filter= ADAPTER(filter);
      var result= $.Deferred();
      var ddgQuery= "http://api.duckduckgo.com/?q=" + filter + "&format=json";

      $.get(ddgQuery,function(j) {},'jsonp')
        .done(function(response) {
          response= response.RelatedTopics;
          var direct= directResults(response);
          var groups= groupedResults(response);

          result.resolve(new Backbone.Collection(direct.concat(groups)));
        });

      return result;
    }

  });
});
{'fraction_non_alphanumeric': 0.14179768614654406, 'fraction_numerical': 0.0008899436369029962, 'mean_word_length': 2.8405466970387243, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '6976439', 'n_tokens_mistral': 1057, 'n_tokens_neox': 1008, 'n_words': 202}