<commit_before>﻿var SearchManager = function(manager) {
    var self = this;
    this.audioManager = manager;
    this.topTracksVk = [];
    this.$infoLoadingSpinner = $('#info-header-spinner');
    this.$vkMusicLoadingSpinner = $('#vkMusic-header-spinner');

    this._search = function() {
        var searchParam = $('#search').val().toLocaleLowerCase();
        $('.vkMusicList').find('.track').remove();
        self.$vkMusicLoadingSpinner.fadeIn('normal');
        $.ajax({
            url: 'api/usertracks/globalsearch?searchText=' + searchParam + "&criteria=" + $('.btn-primary').data('search').toLocaleLowerCase(),
            type: 'GET',
            dataType: 'json',
            success: function (tracks) {
                for (var i = 0; i < tracks.length; i++) {
                    tracks[i].Duration = self._toFormattedTime(tracks[i].Duration, true);
                }
                self._showTracks(tracks, $('#searchTrackTemplate'));
                self.audioManager.refreshTracks();
                self.audioManager.bindPlayBtnListeners();
                $('.vkMusicList > .tableRow > .track-info-btn').click(self._getTrackInfo);
                $('.vkMusicTable').mCustomScrollbar({
                    theme: 'dark-3',
                    scrollButtons: { enable: true },
                    updateOnContentResize: true,
                    scrollInertia: 0,
                    autoHideScrollbar: true,
                    advanced: { updateOnSelectorChange: "true" }
                });
                self.$vkMusicLoadingSpinner.hide();
            }
        });
    };

    this._showTracks = function(tracks, template) {
        $('.vkMusicList').find('.track').detach();
        for (var i = 0; i < tracks.length; i++) {
            var tmpl = template.tmpl(tracks[i]);
            tmpl.appendTo('.vkMusicList');
            if (self.audioManager.$currentTrack !== null
                && self.audioManager.$currentTrack.children('.trackId').html() == tracks[i].id) {
                tmpl.toggleClass('.draggable-item-selected');
                self.audioManager.$currentTrack = tmpl;
                tmpl.append(self.audioManager.progressSlider.getSlider());
                if (self.audioManager.audio.paused) {
                    self.audioManager._setPlayImgButton(tmpl);
                    self.audioManager.$currentTrack.find('.track-duration').show();
                    self.audioManager.$currentTrack.find('.track-remaining').hide();
                } else {
                    self.audioManager._setPauseImgButton(tmpl);
                    self.audioManager.$currentTrack.find('.track-duration').hide();
                    self.audioManager.$currentTrack.find('.track-remaining').show();
                }
            }
        }
    };

    this._getTrackInfo = function () {
        var $self = $(this);
        var author = $self.parent().children('.track-description').children('.track-info');
        var trackName = $self.parent().children('.track-description').children('.track-title');
        self.$infoLoadingSpinner.show();
        $.ajax({
            url: '/api/usertracks/trackinfo?artist=' + author.html() + '&trackName=' + trackName.html(),
            async: true,
            success: function (trackInfo) {
                self.$infoLoadingSpinner.hide();
                var $trackInfoTemplate = $('#trackInfoTemplate');
                var object = $trackInfoTemplate.tmpl(trackInfo);
                var $trackInfoContainer = $('.modal-body');
                $trackInfoContainer.text('');
                object.appendTo($trackInfoContainer);
                if (trackInfo.Lyric != null) {
                    for (var i = 0; i < trackInfo.Lyric.length; i++) {
                        var $p = $('<p>');
                        $p.text(trackInfo.Lyric[i]);
                        $trackInfoContainer.find('.trackLyric').append($p);
                    }
                }
                if (trackInfo.Summary != null) {
                    $trackInfoContainer.find('.trackSummary').append(trackInfo.Summary);
                }
                self.topTracks = trackInfo.ArtistTopTrackList;
                $('#listenTopBtn').attr('disabled', false);
            }
        });
    };

    this._toFormattedTime = function (input, roundSeconds) {
        if (roundSeconds) {
            input = Math.ceil(input);
        }

        var withHours = false;

        if (input >= 60 * 60) {
            withHours = true;
        }

        var hoursString = '00';
        var minutesString = '00';
        var secondsString = '00';
        var hours = 0;
        var minutes = 0;
        var seconds = 0;

        hours = Math.floor(input / (60 * 60));
        input = input % (60 * 60);

        minutes = Math.floor(input / 60);
        input = input % 60;

        seconds = input;

        hoursString = (hours >= 10) ? hours.toString() : '0' + hours.toString();
        minutesString = (minutes >= 10) ? minutes.toString() : '0' + minutes.toString();
        secondsString = (seconds >= 10) ? seconds.toString() : '0' + seconds.toString();

        return ((withHours) ? hoursString + ':' : '') + minutesString + ':' + secondsString;
    };

    this._search();
};

SearchManager.prototype.bindListeners = function () {
    var self = this;

    $('#search').keyup(function () {
        self._search();
    });
<commit_msg>add search timeout<commit_after>﻿var SearchManager = function(manager) {
    var self = this;
    this.audioManager = manager;
    this.topTracksVk = [];
    this.$infoLoadingSpinner = $('#info-header-spinner');
    this.$vkMusicLoadingSpinner = $('#vkMusic-header-spinner');

    this._search = function() {
        var searchParam = $('#search').val().toLocaleLowerCase();
        $('.vkMusicList').find('.track').remove();
        self.$vkMusicLoadingSpinner.fadeIn('normal');
        $.ajax({
            url: 'api/usertracks/globalsearch?searchText=' + searchParam + "&criteria=" + $('.btn-primary').data('search').toLocaleLowerCase(),
            type: 'GET',
            dataType: 'json',
            success: function (tracks) {
                for (var i = 0; i < tracks.length; i++) {
                    tracks[i].Duration = self._toFormattedTime(tracks[i].Duration, true);
                }
                self._showTracks(tracks, $('#searchTrackTemplate'));
                self.audioManager.refreshTracks();
                self.audioManager.bindPlayBtnListeners();
                $('.vkMusicList > .tableRow > .track-info-btn').click(self._getTrackInfo);
                $('.vkMusicTable').mCustomScrollbar({
                    theme: 'dark-3',
                    scrollButtons: { enable: true },
                    updateOnContentResize: true,
                    scrollInertia: 0,
                    autoHideScrollbar: true,
                    advanced: { updateOnSelectorChange: "true" }
                });
                self.$vkMusicLoadingSpinner.hide();
            }
        });
    };

    this._showTracks = function(tracks, template) {
        $('.vkMusicList').find('.track').detach();
        for (var i = 0; i < tracks.length; i++) {
            var tmpl = template.tmpl(tracks[i]);
            tmpl.appendTo('.vkMusicList');
            if (self.audioManager.$currentTrack !== null
                && self.audioManager.$currentTrack.children('.trackId').html() == tracks[i].id) {
                tmpl.toggleClass('.draggable-item-selected');
                self.audioManager.$currentTrack = tmpl;
                tmpl.append(self.audioManager.progressSlider.getSlider());
                if (self.audioManager.audio.paused) {
                    self.audioManager._setPlayImgButton(tmpl);
                    self.audioManager.$currentTrack.find('.track-duration').show();
                    self.audioManager.$currentTrack.find('.track-remaining').hide();
                } else {
                    self.audioManager._setPauseImgButton(tmpl);
                    self.audioManager.$currentTrack.find('.track-duration').hide();
                    self.audioManager.$currentTrack.find('.track-remaining').show();
                }
            }
        }
    };

    this._getTrackInfo = function () {
        var $self = $(this);
        var author = $self.parent().children('.track-description').children('.track-info');
        var trackName = $self.parent().children('.track-description').children('.track-title');
        self.$infoLoadingSpinner.show();
        $.ajax({
            url: '/api/usertracks/trackinfo?artist=' + author.html() + '&trackName=' + trackName.html(),
            async: true,
            success: function(trackInfo) {
                self.$infoLoadingSpinner.hide();
                var $trackInfoTemplate = $('#trackInfoTemplate');
                var object = $trackInfoTemplate.tmpl(trackInfo);
                var $trackInfoContainer = $('.modal-body');
                $trackInfoContainer.text('');
                object.appendTo($trackInfoContainer);
                if (trackInfo.Lyric != null) {
                    for (var i = 0; i < trackInfo.Lyric.length; i++) {
                        var $p = $('<p>');
                        $p.text(trackInfo.Lyric[i]);
                        $trackInfoContainer.find('.trackLyric').append($p);
                    }
                }
                if (trackInfo.Summary != null) {
                    $trackInfoContainer.find('.trackSummary').append(trackInfo.Summary);
                }
                self.topTracks = trackInfo.ArtistTopTrackList;
                $('#listenTopBtn').attr('disabled', false);
            }
        });
    };

    this._toFormattedTime = function (input, roundSeconds) {
        if (roundSeconds) {
            input = Math.ceil(input);
        }

        var withHours = false;

        if (input >= 60 * 60) {
            withHours = true;
        }

        var hoursString = '00';
        var minutesString = '00';
        var secondsString = '00';
        var hours = 0;
        var minutes = 0;
        var seconds = 0;

        hours = Math.floor(input / (60 * 60));
        input = input % (60 * 60);

        minutes = Math.floor(input / 60);
        input = input % 60;

        seconds = input;

        hoursString = (hours >= 10) ? hours.toString() : '0' + hours.toString();
        minutesString = (minutes >= 10) ? minutes.toString() : '0' + minutes.toString();
        secondsString = (seconds >= 10) ? seconds.toString() : '0' + seconds.toString();

        return ((withHours) ? hoursString + ':' : '') + minutesString + ':' + secondsString;
    };

    this._delay = (function () {
        var timer = 0;
        return function (callback, ms) {
            clearTimeout(timer);
            timer = setTimeout(callback, ms);
        }
    })();

    this._search();
};

SearchManager.prototype.bindListeners = function () {
    var self = this;

    $('#search').keyup(function () {
        self._delay(function() {
            self._search();
        }, 1000);
    });

{'fraction_non_alphanumeric': 0.14990048851094626, 'fraction_numerical': 0.007508594174054641, 'mean_word_length': 1.794489383215369, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '3080842', 'n_tokens_mistral': 3082, 'n_tokens_neox': 2870, 'n_words': 494}