<commit_before>"use strict";

angular.module('arethusa.search').service('search', function(state, configurator) {
  var self = this;
  this.conf = configurator.configurationFor('search');
  this.name = this.conf.name;
  this.template = this.conf.template;

  this.queryTokens = function() {
    var tokens = self.tokenQuery.split(' ');
    var ids = arethusaUtil.inject([], tokens, function(memo, token) {
      arethusaUtil.pushAll(memo, self.strings[token]);
    });
    state.multiSelect(ids);
  };

  this.collectTokenStrings = function() {
    return arethusaUtil.inject({}, state.tokens, function(memo, id, token) {
      var str = token.string;
      if (! memo[str]) {
        memo[str] = [];
      }
      memo[str].push(id);
    });
  };
<commit_msg>Enable regex searching in search plugin<commit_after>"use strict";

angular.module('arethusa.search').service('search', function(state, configurator) {
  var self = this;
  this.conf = configurator.configurationFor('search');
  this.name = this.conf.name;
  this.template = this.conf.template;
  this.queryByRegex = this.conf.regex;

  function findByRegex(str) {
    // We might need to escape some chars here, we need to try
    // this out more
    var regex = new RegExp(str, 'i');
    return arethusaUtil.inject([], self.strings, function(memo, string, ids) {
      if (string.match(regex)) {
        arethusaUtil.pushAll(memo, ids);
      }
    });
  }

  this.queryTokens = function() {
    if (self.tokenQuery === '') {
      return;
    }
    var tokens = self.tokenQuery.split(' ');
    var ids = arethusaUtil.inject([], tokens, function(memo, token) {
      var hits = self.queryByRegex ?  findByRegex(token) : self.strings[token];
      arethusaUtil.pushAll(memo, hits);
    });
    state.multiSelect(ids);
  };

  this.collectTokenStrings = function() {
    return arethusaUtil.inject({}, state.tokens, function(memo, id, token) {
      var str = token.string;
      if (! memo[str]) {
        memo[str] = [];
      }
      memo[str].push(id);
    });
  };

{'fraction_non_alphanumeric': 0.1566502463054187, 'fraction_numerical': 0.0, 'mean_word_length': 3.1618852459016393, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7136743', 'n_tokens_mistral': 661, 'n_tokens_neox': 655, 'n_words': 133}