<commit_before>// Models

var SearchTarget = Backbone.Model.extend({

  defaults: {
    features: new Backbone.Collection([]),
    strings: new Backbone.Collection([]),
  },

  reset: function() {
    this.get('features').reset();
    this.get('strings').reset();
  },

  addFeatures: function(names) {
    _.each(names, function(n) {
      if (n.match(/^<.+>.*/i)) {
        var name = n.slice(1, n.indexOf('>'));
        var value = n.slice(n.indexOf('>') + 1);
        this.get('features').add(new Feature({ name: name, value: value }));
      } else {
        this.get('features').add(new Feature({ name: n }));
      }
    }, this);
  },

  addStrings: function(strings) {
    _.each(strings, function(s) {
      this.get('strings').add(new String({ content: s }));
    }, this);
  },

  search: function() {
    this.fetch({
      url: '/search',
      method: 'POST',
      success: function(model, response, options) {
        var matchingRules = _.map(model.get('matchingRules'), function(r) {
          return new Rule({ name: r.name, description: r.description });
        });
        model.set('matchingRules',
                  new Results(matchingRules, { comparator: 'name' }));
        model.trigger('found');
      },
      error: function(model, response, options) {
        model.trigger('notfound');
      },
    });
  },

});

var Feature = Backbone.Model.extend({

  defaults: { value: '' }

});

var String = Backbone.Model.extend({});


var Rule = Backbone.Model.extend({

  initialize: function() {
    this.urlRoot = '/rules';<commit_msg>[Search] Fix: Make sure data to search for gets delivered to the server.<commit_after>// Models

var SearchTarget = Backbone.Model.extend({

  initialize: function() {
    this.urlRoot = '/search';
  },

  defaults: {
    features: new Backbone.Collection([]),
    strings: new Backbone.Collection([]),
  },

  reset: function() {
    this.get('features').reset();
    this.get('strings').reset();
  },

  addFeatures: function(names) {
    _.each(names, function(n) {
      if (n.match(/^<.+>.*/i)) {
        var name = n.slice(1, n.indexOf('>'));
        var value = n.slice(n.indexOf('>') + 1);
        this.get('features').add(new Feature({ name: name, value: value }));
      } else {
        this.get('features').add(new Feature({ name: n }));
      }
    }, this);
  },

  addStrings: function(strings) {
    _.each(strings, function(s) {
      this.get('strings').add(new String({ content: s }));
    }, this);
  },

  search: function() {
    this.save(null, {
      success: function(model, response, options) {
        var matchingRules = _.map(model.get('matchingRules'), function(r) {
          return new Rule({ name: r.name, description: r.description });
        });
        model.set('matchingRules',
                  new Results(matchingRules, { comparator: 'name' }));
        model.trigger('found');
      },
      error: function(model, response, options) {
        model.trigger('notfound');
      },
    });
  },

});

var Feature = Backbone.Model.extend({

  defaults: { value: '' }

});

var String = Backbone.Model.extend({});


var Rule = Backbone.Model.extend({

  initialize: function() {
    this.urlRoot = '/rules';
{'fraction_non_alphanumeric': 0.18872625350358144, 'fraction_numerical': 0.0012457178449081284, 'mean_word_length': 2.6666666666666665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '2323939', 'n_tokens_mistral': 1006, 'n_tokens_neox': 981, 'n_words': 209}