<commit_before>EasySearch = (function () {
  'use strict';

  var ESCounts,
    Searchers,
    indexes = {/** @see defaultOptions */},
    defaultOptions = {
      'format' : 'mongo',
      'skip' : 0,
      'limit' : 10,
      'use' : 'minimongo',
      'reactive' : true,
      'props' : {},
      'sort' : function () {
        if (Searchers[this.use]) {
          return Searchers[this.use].defaultSort(this);
        }

        return {};
      },
      'count' : function () {
        var doc = ESCounts.findOne({ _id : this.name });

        if (doc) {
          return doc.count;
        }

        return 0;
      },
      'changeResults' : function (results) {
        return results;
      },
      /**
       * When using elastic-search it's the query object,
       * while using with mongo-db it's the selector object.
       *
       * @param {String} searchString
       * @return {Object}
       */
      'query' : function (searchString) {
        return Searchers[this.use].defaultQuery(this, searchString);
      }
    };

  ESCounts = new Meteor.Collection('esCounts');

  /** Helper Functions */
  function setUpPublication(name, opts) {
    Meteor.publish(name + '/easySearch', function (conf) {
      var resultSet,
        resultArray = [],
        publishScope = this;

      check(conf, Object);

      // TODO: sanity check each property
      indexes[name].skip = conf.skip;
      indexes[name].limit = conf.limit || indexes[name].limit;
      indexes[name].props = _.extend(indexes[name].props, conf.props);
      indexes[name].publishScope = this;

      resultSet = Searchers[opts.use].search(name, conf.value, indexes[name]);

      ESCounts.update({ _id: name }, { $set: { count: resultSet.total } }, { upsert: true });

      if (resultSet.results.length > 0) {
        if (_.isObject(resultSet.results[0])) {
          resultArray = _.map(resultSet.results, function (doc) {
            return doc._id;
          });
        } else if (_.isString(resultSet.results[0])) {
          resultArray = resultSet.results;
        }

        // properly observe the collection!
        opts.collection
          .find({ _id: { $in: resultArray } }, { sort: indexes[name].sort()})
          .observe({
            added: function (doc) {
              doc._index = name;
              publishScope.added('esSearchResults', doc._id, doc);
            },
            changed: function (doc) {
              publishScope.changed('esSearchResults', doc._id, doc);
            },
            removed: function (doc) {
              publishScope.removed('esSearchResults', doc._id);<commit_msg>Minor changes<commit_after>EasySearch = (function () {
  'use strict';

  var ESCounts,
    Searchers,
    indexes = {/** @see defaultOptions */},
    defaultOptions = {
      'format' : 'mongo',
      'skip' : 0,
      'limit' : 10,
      'use' : 'minimongo',
      'reactive' : true,
      'props' : {},
      'sort' : function () {
        if (Searchers[this.use]) {
          return Searchers[this.use].defaultSort(this);
        }

        return {};
      },
      'count' : function () {
        var doc = ESCounts.findOne({ _id : this.name });

        if (doc) {
          return doc.count;
        }

        return 0;
      },
      'changeResults' : function (results) {
        return results;
      },
      /**
       * When using elastic-search it's the query object,
       * while using with mongo-db it's the selector object.
       *
       * @param {String} searchString
       * @return {Object}
       */
      'query' : function (searchString) {
        return Searchers[this.use].defaultQuery(this, searchString);
      }
    };

  ESCounts = new Mongo.Collection('esCounts');

  /** Helper Functions */
  function setUpPublication(name, opts) {
    Meteor.publish(name + '/easySearch', function (conf) {
      var resultSet,
        resultArray = [],
        publishScope = this;

      check(conf, Object);

      // TODO: sanity check each property
      indexes[name].skip = conf.skip;
      indexes[name].limit = conf.limit || indexes[name].limit;
      indexes[name].props = _.extend(indexes[name].props, conf.props);
      indexes[name].publishScope = this;

      resultSet = Searchers[opts.use].search(name, conf.value, indexes[name]);

      ESCounts.update({ _id: name }, { $set: { count: resultSet.total } }, { upsert: true });

      if (resultSet.results.length > 0) {
        if (_.isObject(resultSet.results[0])) {
          resultArray = _.pluck(resultSet.results, '_id');
        } else if (_.isString(resultSet.results[0])) {
          resultArray = resultSet.results;
        }

        // properly observe the collection!
        opts.collection
          .find({ _id: { $in: resultArray } }, { sort: indexes[name].sort()})
          .observe({
            added: function (doc) {
              doc._index = name;
              publishScope.added('esSearchResults', doc._id, doc);
            },
            changed: function (doc) {
              publishScope.changed('esSearchResults', doc._id, doc);
            },
            removed: function (doc) {
              publishScope.removed('esSearchResults', doc._id);
{'fraction_non_alphanumeric': 0.14324324324324325, 'fraction_numerical': 0.002702702702702703, 'mean_word_length': 2.008710801393728, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7556551', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1500, 'n_words': 329}