<commit_before>var searchModule = angular.module(
  'kabam.search',
  [
    'ui.bootstrap', 'kabam.states'
  ]);

searchModule.config([
  'kabamStatesProvider',
  function(kabamStatesProvider) {
    kabamStatesProvider
      .push([
        {
          name: 'search',
          url: '/search?query',
          templateUrl: '/assets/search/views/index.html',
          controller: 'TypeaheadCtrl'
        }
      ]);
  }
]);

searchModule.controller(
  'TypeaheadCtrl',
  [ '$scope', '$http', '$log', '$state', '$stateParams',
    function ($scope, $http, $log, $state, $stateParams) {

      $scope.getTermsAsync = function(suggestion, callback) {
        $http.jsonp("http://target.monimus.com:6660/search/autocomplete?callback=JSON_CALLBACK&q=" + suggestion)
          .then(function(response) {
            $scope.suggestions = response.data;
            callback(response.data);
          });
      };

      $scope.search = function(term, callback) {
        $http.jsonp("http://target.monimus.com:6660/search?callback=JSON_CALLBACK&q=" + term)
          .then(function(response) {
            $scope.suggestions = response.data;
            callback(response.data);
          });
      };

      $scope.courses = true;
      $scope.documents = true;
      $scope.schools = true;
      $scope.students = true;

      $scope.updater = function(selected) {
        _.defer(function() {
          $scope.$apply(function() {
            $scope.selected = selected;
            $scope.search(selected, function(results) {
              $scope.selected = $scope.selected;
              $scope.results = results.results;
            });
          });
        });
      };

      $scope.submit = function($event) {
        if ($event.keyCode == 13) {
          $scope.topUpdater($scope.selected);
        }
      };

      $scope.topUpdater = function(selected) {
        _.defer(function() {
          $scope.$apply(function() {
            $scope.selected = selected;
            $state.go('search', { query: selected });
          });
        });
      };

      if ($stateParams.query) {
        $scope.selected = $stateParams.query;
        $scope.search($stateParams.query, function(results) {
          $scope.results = results.results;
        });
      } else {
        $scope.selected = undefined;
        $scope.results = {};
      }

      var typeaheadOpts = {
        source: $scope.getTermsAsync,
        items: 20,
        minLength: 2,
        updater: $scope.updater
      };

      var topTypeaheadOpts = {
        source: $scope.getTermsAsync,
        items: 20,
        minLength: 2,
        updater: $scope.topUpdater
      };

      $('input.search-box').typeahead(typeaheadOpts);
      $('input.top-search-box').typeahead(topTypeaheadOpts);

      $scope.suggestions = [];
    }
  ]
);<commit_msg>fix(search): update to new search server<commit_after>angular.module('kabam.search', [])

  .config(['kabamStatesProvider',
    function(kabamStatesProvider) {
      kabamStatesProvider
        .push([
          {
            name: 'search',
            url: '/search?query',
            templateUrl: '/assets/search/views/index.html',
            controller: 'TypeaheadCtrl'
          }
        ]);
    }
  ])

  .controller(
    'TypeaheadCtrl',
    [ '$scope', '$http', '$log', '$timeout', '$state', '$stateParams', 'CONFIG',
      function ($scope, $http, $log, $timeout, $state, $stateParams, CONFIG) {
        var searchURL = CONFIG.searchURL || 'http://172.16.31.10:6660';

        $scope.getTermsAsync = function(suggestion, callback) {
          $http.jsonp(searchURL + '/search/autocomplete?callback=JSON_CALLBACK&q=' + suggestion)
            .then(function(response) {
              $scope.suggestions = response.data;
              callback(response.data);
            });
        };

        $scope.search = function(term, callback) {
          $http.jsonp(searchURL + '/search?callback=JSON_CALLBACK&q=' + term)
            .then(function(response) {
              $scope.suggestions = response.data;
              callback(response.data);
            });
        };

        $scope.courses = true;
        $scope.documents = true;
        $scope.schools = true;
        $scope.students = true;

        $scope.updater = function(selected) {
          $timeout(function() {
            $scope.$apply(function() {
              $scope.selected = selected;
              $scope.search(selected, function(results) {
                $scope.selected = $scope.selected;
                $scope.results = results.results;
              });
            });
          });
        };

        $scope.submit = function($event) {
          if ($event.keyCode == 13) {
            $scope.topUpdater($scope.selected);
          }
        };

        $scope.topUpdater = function(selected) {
          $timeout(function() {
            $scope.$apply(function() {
              $scope.selected = selected;
              $state.go('search', { query: selected });
            });
          });
        };

        if ($stateParams.query) {
          $scope.selected = $stateParams.query;
          $scope.search($stateParams.query, function(results) {
            $scope.results = results.results;
          });
        } else {
          $scope.selected = undefined;
          $scope.results = {};
        }

        var typeaheadOpts = {
          source: $scope.getTermsAsync,
          items: 20,
          minLength: 2,
          updater: $scope.updater
        };

        var topTypeaheadOpts = {
          source: $scope.getTermsAsync,
          items: 20,
          minLength: 2,
          updater: $scope.topUpdater
        };

        $('input.search-box').typeahead(typeaheadOpts);
        $('input.top-search-box').typeahead(topTypeaheadOpts);

        $scope.suggestions = [];
      }
    ]
  );
{'fraction_non_alphanumeric': 0.14783653846153846, 'fraction_numerical': 0.006353021978021978, 'mean_word_length': 1.835929892891918, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '4717323', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1678, 'n_words': 249}