<commit_before>angular.module('cesium.es.blockchain.services', ['cesium.services', 'cesium.es.http.services', 'cesium.es.user.services'])

.factory('esBlockchain', function($rootScope, $q, $timeout, esHttp, csConfig, csSettings, esUser) {
  'ngInject';

  function EsBlockchain() {

    var
      CONSTANTS = {
        DEFAULT_SEARCH_SIZE: 40,
        ES_CORE_API_ENDPOINT: 'ES_CORE_API( ([a-z_][a-z0-9-_.]*))?( ([0-9.]+))?( ([0-9a-f:]+))?( ([0-9]+))'
      },
      FIELDS = {
        MINIMAL: ['number', 'hash', 'medianTime', 'issuer'],
        COMMONS: ['number', 'hash', 'medianTime', 'issuer', 'currency', 'version', 'powMin', 'dividend', 'membersCount', 'identities', 'joiners', 'actives', 'leavers', 'revoked', 'excluded', 'certifications', 'transactions']
      },
      exports = {
        node: {},
        block: {},
        raw: {
          block: {
            search: esHttp.post('/:currency/block/_search'),
            searchText: esHttp.get('/:currency/block/_search?q=:text'),
            get: esHttp.get('/:currency/block/:number/_source')
          }
        },
        regex: {
          ES_CORE_API_ENDPOINT: exact(CONSTANTS.ES_CORE_API_ENDPOINT)
        }
      };

    function exact(regexpContent) {
      return new RegExp('^' + regexpContent + '$');
    }

    exports.node.parseEndPoint = function(endpoint) {
      var matches = REGEX.ES_CORE_API_ENDPOINT.exec(endpoint);
      if (!matches) return;
      return {
        dns: matches[2] || '',
        ipv4: matches[4] || '',
        ipv6: matches[6] || '',
        port: matches[8] || 80
      };
    };


    exports.raw.block.processSearchResult = function(res, options) {
      options = options || {};
      options.excludeCurrent = angular.isDefined(options.excludeCurrent) ? options.excludeCurrent : true;
      options.fillAvatar = angular.isDefined(options.fillAvatar) ? options.fillAvatar : true;
      options.cleanData = angular.isDefined(options.cleanData) ? options.cleanData : true;

      var hasExcludedCurrent = false;
      var hits = res && res.hits ? res.hits.hits.reduce(function(res, hit) {
        if (hit._id == 'current' && options.excludeCurrent) {
          hasExcludedCurrent = true;
          return res;
        }
        if (!hit._source) return res;
        var block = new Block(hit._source);
        if (options.cleanData) {
          block.cleanData(); // release data's arrays
        }
        return res.concat(block);
      }, []) : [];
      var result = {
        hits: hits,
        took: res.took,
        total: res && res.hits && res.hits.total ? (
          options.excludeCurrent ? res.hits.total-1 : res.hits.total) : 0<commit_msg>[fix] Es: search on block has bad total number<commit_after>angular.module('cesium.es.blockchain.services', ['cesium.services', 'cesium.es.http.services', 'cesium.es.user.services'])

.factory('esBlockchain', function($rootScope, $q, $timeout, esHttp, csConfig, csSettings, esUser) {
  'ngInject';

  function EsBlockchain() {

    var
      CONSTANTS = {
        DEFAULT_SEARCH_SIZE: 40,
        ES_CORE_API_ENDPOINT: 'ES_CORE_API( ([a-z_][a-z0-9-_.]*))?( ([0-9.]+))?( ([0-9a-f:]+))?( ([0-9]+))'
      },
      FIELDS = {
        MINIMAL: ['number', 'hash', 'medianTime', 'issuer'],
        COMMONS: ['number', 'hash', 'medianTime', 'issuer', 'currency', 'version', 'powMin', 'dividend', 'membersCount', 'identities', 'joiners', 'actives', 'leavers', 'revoked', 'excluded', 'certifications', 'transactions']
      },
      exports = {
        node: {},
        block: {},
        raw: {
          block: {
            search: esHttp.post('/:currency/block/_search'),
            searchText: esHttp.get('/:currency/block/_search?q=:text'),
            get: esHttp.get('/:currency/block/:number/_source')
          }
        },
        regex: {
          ES_CORE_API_ENDPOINT: exact(CONSTANTS.ES_CORE_API_ENDPOINT)
        }
      };

    function exact(regexpContent) {
      return new RegExp('^' + regexpContent + '$');
    }

    exports.node.parseEndPoint = function(endpoint) {
      var matches = REGEX.ES_CORE_API_ENDPOINT.exec(endpoint);
      if (!matches) return;
      return {
        dns: matches[2] || '',
        ipv4: matches[4] || '',
        ipv6: matches[6] || '',
        port: matches[8] || 80
      };
    };


    exports.raw.block.processSearchResult = function(res, options) {
      options = options || {};
      options.excludeCurrent = angular.isDefined(options.excludeCurrent) ? options.excludeCurrent : true;
      options.fillAvatar = angular.isDefined(options.fillAvatar) ? options.fillAvatar : true;
      options.cleanData = angular.isDefined(options.cleanData) ? options.cleanData : true;

      var hasExcludedCurrent = false;
      var hits = res && res.hits ? res.hits.hits.reduce(function(res, hit) {
        if (hit._id == 'current' && options.excludeCurrent) {
          hasExcludedCurrent = true;
          return res;
        }
        if (!hit._source) return res;
        var block = new Block(hit._source);
        if (options.cleanData) {
          block.cleanData(); // release data's arrays
        }
        return res.concat(block);
      }, []) : [];
      var result = {
        hits: hits,
        took: res.took,
        total: res && res.hits && res.hits.total ? (
          hasExcludedCurrent ? res.hits.total-1 : res.hits.total) : 0
{'fraction_non_alphanumeric': 0.1652027658381611, 'fraction_numerical': 0.007475238273219959, 'mean_word_length': 2.530343007915567, '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': '4817254', 'n_tokens_mistral': 1749, 'n_tokens_neox': 1702, 'n_words': 309}