<commit_before>formsAngular.controller('SearchCtrl', ['$scope', '$http', function ($scope, $http) {

    $scope.results = [];
    $scope.moreCount = 0;

    $scope.$watch('searchTarget', function(newValue) {
        if (newValue && newValue.length > 0) {
            $http.get('api/search?q=' + newValue).success(function (data) {
                $scope.results = data.results;
                $scope.moreCount = data.moreCount;
                $scope.errorClass = $scope.results.length === 0 ? "error" : "";
            }).error(function (data, status) {
                console.log("Error in searchbox.js : " + data + ' (status=' + status + ')');
            });
        } else {
            $scope.errorClass = "";
            $scope.results = [];
        }
    },true);

    $scope.$on("$routeChangeStart", function (event, next) {
        $scope.searchTarget = '';
    });

}]);<commit_msg>Make searchbox disappear when searchTarget is empty<commit_after>formsAngular.controller('SearchCtrl', ['$scope', '$http', function ($scope, $http) {

    $scope.results = [];
    $scope.moreCount = 0;

    var clearSearchResults = function() {
        $scope.errorClass = "";
        $scope.results = [];
    };

    $scope.$watch('searchTarget', function(newValue) {
        if (newValue && newValue.length > 0) {
            $http.get('api/search?q=' + newValue).success(function (data) {
                if ($scope.searchTarget.length > 0) {
                    $scope.results = data.results;
                    $scope.moreCount = data.moreCount;
                    $scope.errorClass = $scope.results.length === 0 ? "error" : "";
                } else {
                    clearSearchResults();
                }
            }).error(function (data, status) {
                console.log("Error in searchbox.js : " + data + ' (status=' + status + ')');
            });
        } else {
            clearSearchResults();
        }
    },true);

    $scope.$on("$routeChangeStart", function () {
        $scope.searchTarget = '';
    });

}]);
{'fraction_non_alphanumeric': 0.17172211350293543, 'fraction_numerical': 0.003424657534246575, 'mean_word_length': 1.946685878962536, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '4488567', 'n_tokens_mistral': 592, 'n_tokens_neox': 565, 'n_words': 101}