Commit a68c824f authored by Leonardo Menezes's avatar Leonardo Menezes
Browse files

created data service for analysis module

parent e5a658cf
Loading
Loading
Loading
Loading
+42 −31
Original line number Original line Diff line number Diff line
@@ -189,8 +189,8 @@ angular.module('cerebro').controller('AliasesController', ['$scope',
]);
]);


angular.module('cerebro').controller('AnalysisController', ['$scope',
angular.module('cerebro').controller('AnalysisController', ['$scope',
  '$location', '$timeout', 'AlertService', 'DataService',
  '$location', '$timeout', 'AlertService', 'AnalysisDataService',
  function($scope, $location, $timeout, AlertService, DataService) {
  function($scope, $location, $timeout, AlertService, AnalysisDataService) {


    $scope.analyzerAnalysis = {index: undefined, analyzer: undefined};
    $scope.analyzerAnalysis = {index: undefined, analyzer: undefined};
    $scope.propertyAnalysis = {index: undefined, field: undefined};
    $scope.propertyAnalysis = {index: undefined, field: undefined};
@@ -200,7 +200,7 @@ angular.module('cerebro').controller('AnalysisController', ['$scope',
    $scope.analyzers = [];
    $scope.analyzers = [];


    $scope.loadAnalyzers = function(index) {
    $scope.loadAnalyzers = function(index) {
      DataService.getIndexAnalyzers(index,
      AnalysisDataService.getIndexAnalyzers(index,
        function(analyzers) {
        function(analyzers) {
          $scope.analyzers = analyzers;
          $scope.analyzers = analyzers;
        },
        },
@@ -212,7 +212,7 @@ angular.module('cerebro').controller('AnalysisController', ['$scope',
    };
    };


    $scope.loadFields = function(index) {
    $scope.loadFields = function(index) {
      DataService.getIndexFields(index,
      AnalysisDataService.getIndexFields(index,
        function(fields) {
        function(fields) {
          $scope.fields = fields;
          $scope.fields = fields;
        },
        },
@@ -232,7 +232,7 @@ angular.module('cerebro').controller('AnalysisController', ['$scope',
        var error = function(error) {
        var error = function(error) {
          AlertService.error('Error analyzing text by field', error);
          AlertService.error('Error analyzing text by field', error);
        };
        };
        DataService.analyzeByField(index, field, text, success, error);
        AnalysisDataService.analyzeByField(index, field, text, success, error);
      }
      }
    };
    };


@@ -245,12 +245,17 @@ angular.module('cerebro').controller('AnalysisController', ['$scope',
        var error = function(error) {
        var error = function(error) {
          AlertService.error('Error analyzing text by analyzer', error);
          AlertService.error('Error analyzing text by analyzer', error);
        };
        };
        DataService.analyzeByAnalyzer(index, analyzer, text, success, error);
        AnalysisDataService.analyzeByAnalyzer(
          index,
          analyzer,
          text,
          success, error
        );
      }
      }
    };
    };


    $scope.setup = function() {
    $scope.setup = function() {
      DataService.getOpenIndices(
      AnalysisDataService.getOpenIndices(
        function(indices) {
        function(indices) {
          $scope.indices = indices;
          $scope.indices = indices;
        },
        },
@@ -263,6 +268,36 @@ angular.module('cerebro').controller('AnalysisController', ['$scope',
  }
  }
]);
]);


angular.module('cerebro').factory('AnalysisDataService', ['DataService',
  function(DataService) {

    this.getOpenIndices = function(success, error) {
      DataService.send('analysis/indices', {}, success, error);
    };

    this.getIndexAnalyzers = function(index, success, error) {
      DataService.send('analysis/analyzers', {index: index}, success, error);
    };

    this.getIndexFields = function(index, success, error) {
      DataService.send('analysis/fields', {index: index}, success, error);
    };

    this.analyzeByField = function(index, field, text, success, error) {
      var data = {index: index, field: field, text: text};
      DataService.send('analysis/analyze/field', data, success, error);
    };

    this.analyzeByAnalyzer = function(index, analyzer, text, success, error) {
      var data = {index: index, analyzer: analyzer, text: text};
      DataService.send('analysis/analyze/analyzer', data, success, error);
    };

    return this;

  }
]);

angular.module('cerebro').directive('analysisTokens', function() {
angular.module('cerebro').directive('analysisTokens', function() {
  return {
  return {
    scope: {
    scope: {
@@ -2682,31 +2717,7 @@ angular.module('cerebro').factory('DataService', ['$rootScope', '$timeout',
      clusterRequest('commons/nodes', {}, success, error);
      clusterRequest('commons/nodes', {}, success, error);
    };
    };


    // ---------- Analysis ----------
    this.getOpenIndices = function(success, error) {
      clusterRequest('analysis/indices', {}, success, error);
    };

    this.getIndexAnalyzers = function(index, success, error) {
      clusterRequest('analysis/analyzers', {index: index}, success, error);
    };

    this.getIndexFields = function(index, success, error) {
      clusterRequest('analysis/fields', {index: index}, success, error);
    };

    this.analyzeByField = function(index, field, text, success, error) {
      var data = {index: index, field: field, text: text};
      clusterRequest('analysis/analyze/field', data, success, error);
    };

    this.analyzeByAnalyzer = function(index, analyzer, text, success, error) {
      var data = {index: index, analyzer: analyzer, text: text};
      clusterRequest('analysis/analyze/analyzer', data, success, error);
    };

    // ---------- Aliases ----------
    // ---------- Aliases ----------

    this.getAliases = function(success, error) {
    this.getAliases = function(success, error) {
      clusterRequest('aliases/get_aliases', {}, success, error);
      clusterRequest('aliases/get_aliases', {}, success, error);
    };
    };
+12 −7
Original line number Original line Diff line number Diff line
angular.module('cerebro').controller('AnalysisController', ['$scope',
angular.module('cerebro').controller('AnalysisController', ['$scope',
  '$location', '$timeout', 'AlertService', 'DataService',
  '$location', '$timeout', 'AlertService', 'AnalysisDataService',
  function($scope, $location, $timeout, AlertService, DataService) {
  function($scope, $location, $timeout, AlertService, AnalysisDataService) {


    $scope.analyzerAnalysis = {index: undefined, analyzer: undefined};
    $scope.analyzerAnalysis = {index: undefined, analyzer: undefined};
    $scope.propertyAnalysis = {index: undefined, field: undefined};
    $scope.propertyAnalysis = {index: undefined, field: undefined};
@@ -10,7 +10,7 @@ angular.module('cerebro').controller('AnalysisController', ['$scope',
    $scope.analyzers = [];
    $scope.analyzers = [];


    $scope.loadAnalyzers = function(index) {
    $scope.loadAnalyzers = function(index) {
      DataService.getIndexAnalyzers(index,
      AnalysisDataService.getIndexAnalyzers(index,
        function(analyzers) {
        function(analyzers) {
          $scope.analyzers = analyzers;
          $scope.analyzers = analyzers;
        },
        },
@@ -22,7 +22,7 @@ angular.module('cerebro').controller('AnalysisController', ['$scope',
    };
    };


    $scope.loadFields = function(index) {
    $scope.loadFields = function(index) {
      DataService.getIndexFields(index,
      AnalysisDataService.getIndexFields(index,
        function(fields) {
        function(fields) {
          $scope.fields = fields;
          $scope.fields = fields;
        },
        },
@@ -42,7 +42,7 @@ angular.module('cerebro').controller('AnalysisController', ['$scope',
        var error = function(error) {
        var error = function(error) {
          AlertService.error('Error analyzing text by field', error);
          AlertService.error('Error analyzing text by field', error);
        };
        };
        DataService.analyzeByField(index, field, text, success, error);
        AnalysisDataService.analyzeByField(index, field, text, success, error);
      }
      }
    };
    };


@@ -55,12 +55,17 @@ angular.module('cerebro').controller('AnalysisController', ['$scope',
        var error = function(error) {
        var error = function(error) {
          AlertService.error('Error analyzing text by analyzer', error);
          AlertService.error('Error analyzing text by analyzer', error);
        };
        };
        DataService.analyzeByAnalyzer(index, analyzer, text, success, error);
        AnalysisDataService.analyzeByAnalyzer(
          index,
          analyzer,
          text,
          success, error
        );
      }
      }
    };
    };


    $scope.setup = function() {
    $scope.setup = function() {
      DataService.getOpenIndices(
      AnalysisDataService.getOpenIndices(
        function(indices) {
        function(indices) {
          $scope.indices = indices;
          $scope.indices = indices;
        },
        },
+29 −0
Original line number Original line Diff line number Diff line
angular.module('cerebro').factory('AnalysisDataService', ['DataService',
  function(DataService) {

    this.getOpenIndices = function(success, error) {
      DataService.send('analysis/indices', {}, success, error);
    };

    this.getIndexAnalyzers = function(index, success, error) {
      DataService.send('analysis/analyzers', {index: index}, success, error);
    };

    this.getIndexFields = function(index, success, error) {
      DataService.send('analysis/fields', {index: index}, success, error);
    };

    this.analyzeByField = function(index, field, text, success, error) {
      var data = {index: index, field: field, text: text};
      DataService.send('analysis/analyze/field', data, success, error);
    };

    this.analyzeByAnalyzer = function(index, analyzer, text, success, error) {
      var data = {index: index, analyzer: analyzer, text: text};
      DataService.send('analysis/analyze/analyzer', data, success, error);
    };

    return this;

  }
]);
+0 −24
Original line number Original line Diff line number Diff line
@@ -50,31 +50,7 @@ angular.module('cerebro').factory('DataService', ['$rootScope', '$timeout',
      clusterRequest('commons/nodes', {}, success, error);
      clusterRequest('commons/nodes', {}, success, error);
    };
    };


    // ---------- Analysis ----------
    this.getOpenIndices = function(success, error) {
      clusterRequest('analysis/indices', {}, success, error);
    };

    this.getIndexAnalyzers = function(index, success, error) {
      clusterRequest('analysis/analyzers', {index: index}, success, error);
    };

    this.getIndexFields = function(index, success, error) {
      clusterRequest('analysis/fields', {index: index}, success, error);
    };

    this.analyzeByField = function(index, field, text, success, error) {
      var data = {index: index, field: field, text: text};
      clusterRequest('analysis/analyze/field', data, success, error);
    };

    this.analyzeByAnalyzer = function(index, analyzer, text, success, error) {
      var data = {index: index, analyzer: analyzer, text: text};
      clusterRequest('analysis/analyze/analyzer', data, success, error);
    };

    // ---------- Aliases ----------
    // ---------- Aliases ----------

    this.getAliases = function(success, error) {
    this.getAliases = function(success, error) {
      clusterRequest('aliases/get_aliases', {}, success, error);
      clusterRequest('aliases/get_aliases', {}, success, error);
    };
    };
+44 −44
Original line number Original line Diff line number Diff line
@@ -6,11 +6,11 @@ describe('AnalysisController', function() {
    this.scope = $rootScope.$new();
    this.scope = $rootScope.$new();
    this.$location = $injector.get('$location');
    this.$location = $injector.get('$location');
    this.$timeout = $injector.get('$timeout');
    this.$timeout = $injector.get('$timeout');
    this.DataService = $injector.get('DataService');
    this.AnalysisDataService = $injector.get('AnalysisDataService');
    this.AlertService = $injector.get('AlertService');
    this.AlertService = $injector.get('AlertService');
    this.createController = function() {
    this.createController = function() {
      return $controller('AnalysisController',
      return $controller('AnalysisController',
        {$scope: this.scope}, this.$location, this.$timeout, this.AlertService, this.DataService);
        {$scope: this.scope}, this.$location, this.$timeout, this.AlertService, this.AnalysisDataService);
    };
    };
    this._controller = this.createController();
    this._controller = this.createController();
  }));
  }));
@@ -26,23 +26,23 @@ describe('AnalysisController', function() {
  describe('setup', function() {
  describe('setup', function() {
    it('loads list of open indices', function () {
    it('loads list of open indices', function () {
      var indices = ['index1', 'index2'];
      var indices = ['index1', 'index2'];
      this.DataService.getOpenIndices = function(success, error) {
      this.AnalysisDataService.getOpenIndices = function(success, error) {
        success(indices);
        success(indices);
      };
      };
      spyOn(this.DataService, "getOpenIndices").andCallThrough();
      spyOn(this.AnalysisDataService, "getOpenIndices").andCallThrough();
      this.scope.setup();
      this.scope.setup();
      expect(this.DataService.getOpenIndices).toHaveBeenCalledWith(jasmine.any(Function), jasmine.any(Function));
      expect(this.AnalysisDataService.getOpenIndices).toHaveBeenCalledWith(jasmine.any(Function), jasmine.any(Function));
      expect(this.scope.indices).toEqual(indices);
      expect(this.scope.indices).toEqual(indices);
    });
    });


    it('warns in case loading indices fails', function () {
    it('warns in case loading indices fails', function () {
      this.DataService.getOpenIndices = function(success, error) {
      this.AnalysisDataService.getOpenIndices = function(success, error) {
        error('kaput');
        error('kaput');
      };
      };
      spyOn(this.DataService, "getOpenIndices").andCallThrough();
      spyOn(this.AnalysisDataService, "getOpenIndices").andCallThrough();
      spyOn(this.AlertService, "error").andCallThrough();
      spyOn(this.AlertService, "error").andCallThrough();
      this.scope.setup();
      this.scope.setup();
      expect(this.DataService.getOpenIndices).toHaveBeenCalledWith(jasmine.any(Function), jasmine.any(Function));
      expect(this.AnalysisDataService.getOpenIndices).toHaveBeenCalledWith(jasmine.any(Function), jasmine.any(Function));
      expect(this.AlertService.error).toHaveBeenCalledWith('Error loading indices', 'kaput');
      expect(this.AlertService.error).toHaveBeenCalledWith('Error loading indices', 'kaput');
    });
    });
  });
  });
@@ -50,34 +50,34 @@ describe('AnalysisController', function() {
  describe('loadAnalyzers', function() {
  describe('loadAnalyzers', function() {
    it('loads analyzers for given index', function () {
    it('loads analyzers for given index', function () {
      var analyzers = ['analyzer', 'analyzer2'];
      var analyzers = ['analyzer', 'analyzer2'];
      this.DataService.getIndexAnalyzers = function(index, success, error) {
      this.AnalysisDataService.getIndexAnalyzers = function(index, success, error) {
        success(analyzers);
        success(analyzers);
      };
      };
      spyOn(this.DataService, "getIndexAnalyzers").andCallThrough();
      spyOn(this.AnalysisDataService, "getIndexAnalyzers").andCallThrough();
      this.scope.loadAnalyzers('some index');
      this.scope.loadAnalyzers('some index');
      expect(this.DataService.getIndexAnalyzers).toHaveBeenCalledWith('some index', jasmine.any(Function), jasmine.any(Function));
      expect(this.AnalysisDataService.getIndexAnalyzers).toHaveBeenCalledWith('some index', jasmine.any(Function), jasmine.any(Function));
      expect(this.scope.analyzers).toEqual(analyzers);
      expect(this.scope.analyzers).toEqual(analyzers);
    });
    });


    it('alerts about error loading analyzers', function () {
    it('alerts about error loading analyzers', function () {
      this.DataService.getIndexAnalyzers = function(index, success, error) {
      this.AnalysisDataService.getIndexAnalyzers = function(index, success, error) {
        error('kaput');
        error('kaput');
      };
      };
      spyOn(this.DataService, "getIndexAnalyzers").andCallThrough();
      spyOn(this.AnalysisDataService, "getIndexAnalyzers").andCallThrough();
      spyOn(this.AlertService, "error").andCallThrough();
      spyOn(this.AlertService, "error").andCallThrough();
      this.scope.loadAnalyzers('some index');
      this.scope.loadAnalyzers('some index');
      expect(this.DataService.getIndexAnalyzers).toHaveBeenCalledWith('some index', jasmine.any(Function), jasmine.any(Function));
      expect(this.AnalysisDataService.getIndexAnalyzers).toHaveBeenCalledWith('some index', jasmine.any(Function), jasmine.any(Function));
      expect(this.AlertService.error).toHaveBeenCalledWith('Error loading index analyzers', 'kaput');
      expect(this.AlertService.error).toHaveBeenCalledWith('Error loading index analyzers', 'kaput');
    });
    });


    it('resets analyzers in case index analyzers fail to load', function () {
    it('resets analyzers in case index analyzers fail to load', function () {
      this.DataService.getIndexAnalyzers = function(index, success, error) {
      this.AnalysisDataService.getIndexAnalyzers = function(index, success, error) {
        error('kaput');
        error('kaput');
      };
      };
      this.scope.analyzers = ['one'];
      this.scope.analyzers = ['one'];
      spyOn(this.DataService, "getIndexAnalyzers").andCallThrough();
      spyOn(this.AnalysisDataService, "getIndexAnalyzers").andCallThrough();
      this.scope.loadAnalyzers('some index');
      this.scope.loadAnalyzers('some index');
      expect(this.DataService.getIndexAnalyzers).toHaveBeenCalledWith('some index', jasmine.any(Function), jasmine.any(Function));
      expect(this.AnalysisDataService.getIndexAnalyzers).toHaveBeenCalledWith('some index', jasmine.any(Function), jasmine.any(Function));
      expect(this.scope.analyzers).toEqual([]);
      expect(this.scope.analyzers).toEqual([]);
    });
    });
  });
  });
@@ -85,34 +85,34 @@ describe('AnalysisController', function() {
  describe('loadFields', function() {
  describe('loadFields', function() {
    it('loads fields for given index', function () {
    it('loads fields for given index', function () {
      var fields = ['field1', 'field2'];
      var fields = ['field1', 'field2'];
      this.DataService.getIndexFields = function(index, success, error) {
      this.AnalysisDataService.getIndexFields = function(index, success, error) {
        success(fields);
        success(fields);
      };
      };
      spyOn(this.DataService, "getIndexFields").andCallThrough();
      spyOn(this.AnalysisDataService, "getIndexFields").andCallThrough();
      this.scope.loadFields('some index');
      this.scope.loadFields('some index');
      expect(this.DataService.getIndexFields).toHaveBeenCalledWith('some index', jasmine.any(Function), jasmine.any(Function));
      expect(this.AnalysisDataService.getIndexFields).toHaveBeenCalledWith('some index', jasmine.any(Function), jasmine.any(Function));
      expect(this.scope.fields).toEqual(fields);
      expect(this.scope.fields).toEqual(fields);
    });
    });


    it('alerts about error loading analyzers', function () {
    it('alerts about error loading analyzers', function () {
      this.DataService.getIndexFields = function(index, success, error) {
      this.AnalysisDataService.getIndexFields = function(index, success, error) {
        error('kaput');
        error('kaput');
      };
      };
      spyOn(this.DataService, "getIndexFields").andCallThrough();
      spyOn(this.AnalysisDataService, "getIndexFields").andCallThrough();
      spyOn(this.AlertService, "error").andCallThrough();
      spyOn(this.AlertService, "error").andCallThrough();
      this.scope.loadFields('some index');
      this.scope.loadFields('some index');
      expect(this.DataService.getIndexFields).toHaveBeenCalledWith('some index', jasmine.any(Function), jasmine.any(Function));
      expect(this.AnalysisDataService.getIndexFields).toHaveBeenCalledWith('some index', jasmine.any(Function), jasmine.any(Function));
      expect(this.AlertService.error).toHaveBeenCalledWith('Error loading index fields', 'kaput');
      expect(this.AlertService.error).toHaveBeenCalledWith('Error loading index fields', 'kaput');
    });
    });


    it('resets analyzers in case index analyzers fail to load', function () {
    it('resets analyzers in case index analyzers fail to load', function () {
      this.DataService.getIndexFields = function(index, success, error) {
      this.AnalysisDataService.getIndexFields = function(index, success, error) {
        error('kaput');
        error('kaput');
      };
      };
      this.scope.analyzers = ['one'];
      this.scope.analyzers = ['one'];
      spyOn(this.DataService, "getIndexFields").andCallThrough();
      spyOn(this.AnalysisDataService, "getIndexFields").andCallThrough();
      this.scope.loadFields('some index');
      this.scope.loadFields('some index');
      expect(this.DataService.getIndexFields).toHaveBeenCalledWith('some index', jasmine.any(Function), jasmine.any(Function));
      expect(this.AnalysisDataService.getIndexFields).toHaveBeenCalledWith('some index', jasmine.any(Function), jasmine.any(Function));
      expect(this.scope.fields).toEqual([]);
      expect(this.scope.fields).toEqual([]);
    });
    });
  });
  });
@@ -120,33 +120,33 @@ describe('AnalysisController', function() {
  describe('analyzeByField', function() {
  describe('analyzeByField', function() {
    it('analyzes text by field', function () {
    it('analyzes text by field', function () {
      var tokens = ['t', 't2'];
      var tokens = ['t', 't2'];
      this.DataService.analyzeByField = function(index, field, text, success, error) {
      this.AnalysisDataService.analyzeByField = function(index, field, text, success, error) {
        success(tokens);
        success(tokens);
      };
      };
      spyOn(this.DataService, "analyzeByField").andCallThrough();
      spyOn(this.AnalysisDataService, "analyzeByField").andCallThrough();
      this.scope.analyzeByField('idx', 'fld', 'txt');
      this.scope.analyzeByField('idx', 'fld', 'txt');
      expect(this.DataService.analyzeByField).toHaveBeenCalledWith('idx', 'fld', 'txt', jasmine.any(Function), jasmine.any(Function));
      expect(this.AnalysisDataService.analyzeByField).toHaveBeenCalledWith('idx', 'fld', 'txt', jasmine.any(Function), jasmine.any(Function));
      expect(this.scope.field_tokens).toEqual(tokens);
      expect(this.scope.field_tokens).toEqual(tokens);
    });
    });


    it('alerts about error during analysis', function () {
    it('alerts about error during analysis', function () {
      this.DataService.analyzeByField = function(index, field, text, success, error) {
      this.AnalysisDataService.analyzeByField = function(index, field, text, success, error) {
        error('kaput');
        error('kaput');
      };
      };
      spyOn(this.DataService, "analyzeByField").andCallThrough();
      spyOn(this.AnalysisDataService, "analyzeByField").andCallThrough();
      spyOn(this.AlertService, "error").andCallThrough();
      spyOn(this.AlertService, "error").andCallThrough();
      this.scope.analyzeByField('idx', 'fld', 'txt');
      this.scope.analyzeByField('idx', 'fld', 'txt');
      expect(this.DataService.analyzeByField).toHaveBeenCalledWith('idx', 'fld', 'txt', jasmine.any(Function), jasmine.any(Function));
      expect(this.AnalysisDataService.analyzeByField).toHaveBeenCalledWith('idx', 'fld', 'txt', jasmine.any(Function), jasmine.any(Function));
      expect(this.AlertService.error).toHaveBeenCalledWith('Error analyzing text by field', 'kaput');
      expect(this.AlertService.error).toHaveBeenCalledWith('Error analyzing text by field', 'kaput');
    });
    });


    it('resets analyzers in case index analyzers fail to load', function () {
    it('resets analyzers in case index analyzers fail to load', function () {
      this.DataService.analyzeByField = function(index, field, text, success, error) {
      this.AnalysisDataService.analyzeByField = function(index, field, text, success, error) {
        error('kaput');
        error('kaput');
      };
      };
      spyOn(this.DataService, "analyzeByField").andCallThrough();
      spyOn(this.AnalysisDataService, "analyzeByField").andCallThrough();
      this.scope.analyzeByField('idx', 'fld', 'txt');
      this.scope.analyzeByField('idx', 'fld', 'txt');
      expect(this.DataService.analyzeByField).toHaveBeenCalledWith('idx', 'fld', 'txt', jasmine.any(Function), jasmine.any(Function));
      expect(this.AnalysisDataService.analyzeByField).toHaveBeenCalledWith('idx', 'fld', 'txt', jasmine.any(Function), jasmine.any(Function));
      expect(this.scope.field_tokens).toEqual(undefined);
      expect(this.scope.field_tokens).toEqual(undefined);
    });
    });
  });
  });
@@ -154,33 +154,33 @@ describe('AnalysisController', function() {
  describe('analyzeByAnalyzer', function() {
  describe('analyzeByAnalyzer', function() {
    it('analyzes text', function () {
    it('analyzes text', function () {
      var tokens = ['t', 't2'];
      var tokens = ['t', 't2'];
      this.DataService.analyzeByAnalyzer = function(index, analyzer, text, success, error) {
      this.AnalysisDataService.analyzeByAnalyzer = function(index, analyzer, text, success, error) {
        success(tokens);
        success(tokens);
      };
      };
      spyOn(this.DataService, "analyzeByAnalyzer").andCallThrough();
      spyOn(this.AnalysisDataService, "analyzeByAnalyzer").andCallThrough();
      this.scope.analyzeByAnalyzer('idx', 'fld', 'txt');
      this.scope.analyzeByAnalyzer('idx', 'fld', 'txt');
      expect(this.DataService.analyzeByAnalyzer).toHaveBeenCalledWith('idx', 'fld', 'txt', jasmine.any(Function), jasmine.any(Function));
      expect(this.AnalysisDataService.analyzeByAnalyzer).toHaveBeenCalledWith('idx', 'fld', 'txt', jasmine.any(Function), jasmine.any(Function));
      expect(this.scope.analyzer_tokens).toEqual(tokens);
      expect(this.scope.analyzer_tokens).toEqual(tokens);
    });
    });


    it('alerts about error during analysis', function () {
    it('alerts about error during analysis', function () {
      this.DataService.analyzeByAnalyzer = function(index, analyzer, text, success, error) {
      this.AnalysisDataService.analyzeByAnalyzer = function(index, analyzer, text, success, error) {
        error('kaput');
        error('kaput');
      };
      };
      spyOn(this.DataService, "analyzeByAnalyzer").andCallThrough();
      spyOn(this.AnalysisDataService, "analyzeByAnalyzer").andCallThrough();
      spyOn(this.AlertService, "error").andCallThrough();
      spyOn(this.AlertService, "error").andCallThrough();
      this.scope.analyzeByAnalyzer('idx', 'fld', 'txt');
      this.scope.analyzeByAnalyzer('idx', 'fld', 'txt');
      expect(this.DataService.analyzeByAnalyzer).toHaveBeenCalledWith('idx', 'fld', 'txt', jasmine.any(Function), jasmine.any(Function));
      expect(this.AnalysisDataService.analyzeByAnalyzer).toHaveBeenCalledWith('idx', 'fld', 'txt', jasmine.any(Function), jasmine.any(Function));
      expect(this.AlertService.error).toHaveBeenCalledWith('Error analyzing text by analyzer', 'kaput');
      expect(this.AlertService.error).toHaveBeenCalledWith('Error analyzing text by analyzer', 'kaput');
    });
    });


    it('resets analyzers in case index analyzers fail to load', function () {
    it('resets analyzers in case index analyzers fail to load', function () {
      this.DataService.analyzeByAnalyzer = function(index, analyzer, text, success, error) {
      this.AnalysisDataService.analyzeByAnalyzer = function(index, analyzer, text, success, error) {
        error('kaput');
        error('kaput');
      };
      };
      spyOn(this.DataService, "analyzeByAnalyzer").andCallThrough();
      spyOn(this.AnalysisDataService, "analyzeByAnalyzer").andCallThrough();
      this.scope.analyzeByAnalyzer('idx', 'fld', 'txt');
      this.scope.analyzeByAnalyzer('idx', 'fld', 'txt');
      expect(this.DataService.analyzeByAnalyzer).toHaveBeenCalledWith('idx', 'fld', 'txt', jasmine.any(Function), jasmine.any(Function));
      expect(this.AnalysisDataService.analyzeByAnalyzer).toHaveBeenCalledWith('idx', 'fld', 'txt', jasmine.any(Function), jasmine.any(Function));
      expect(this.scope.analyzer_tokens).toEqual(undefined);
      expect(this.scope.analyzer_tokens).toEqual(undefined);
    });
    });
  });
  });