<commit_before>Template.search.events({
    'submit form': function(event){
    var o = "http://www.omdbapi.com/?type=movie&s=";
    var s = document.getElementById("search").value;
    var u = o + s;
         (function() {   
         $.getJSON(u)
            .done(function(data) {
             
            MovieSearch._collection.remove({}); 
            document.getElementById("search").blur();
             try {
                 var len = data['Search'].length;
             }
             catch(err) {
                var info = '<p>Hmm we got no results...<a href="javascript:document.getElementById(\'search\').focus()" class="alert-link">try again!</a></p>';
                document.getElementById("info").setAttribute("class", "alert alert-warning");
                document.getElementById("info").innerHTML = info;
                 
                var list = document.getElementById("results");
                while (list.firstChild) {
                    list.removeChild(list.firstChild);
                }
                var mg = ""
                document.getElementById("overview").innerHTML = mg 
                return;
             }
            var mg = "<br><h3>Results from the OMDB:</h3>"
            document.getElementById("overview").innerHTML = mg;

            var list = document.getElementById("results");
            while (list.firstChild) {
                list.removeChild(list.firstChild);
            }
            for (i = 0; i < data['Search'].length; i++) {
                var t = data['Search'][i]['Title'];
                var y = data['Search'][i]['Year'];
                var imdb = data['Search'][i]['imdbID'];
                var ty = t + " (" + y + ")";

                var d = document.createElement("div");
                d.setAttribute("class", "radio")
                d.setAttribute("id", "for" + i);
                document.getElementById("results").appendChild(d);

                var l = document.createElement("label");
                l.setAttribute("for", imdb);
                l.setAttribute("id", "for" + imdb);
                document.getElementById("for" + i).appendChild(l);

                var n = document.createElement("input");
                n.setAttribute("type", "radio");
                n.setAttribute("value", ty);
                n.setAttribute("id", imdb);
                n.setAttribute("name", "movie");
                n.setAttribute("class", "movie");
                n.required = true;
                document.getElementById("for" + imdb).appendChild(n);

                old_html = document.getElementById("for" + imdb).innerHTML;
                ty = "<p>" + ty + "</p>"
                document.getElementById("for" + imdb).innerHTML = old_html + ty;

                var info = '<p>Not find what you were looking for? <a href="javascript:document.getElementById(\'search\').focus()" >Click here to search again!</a></p>';
                document.getElementById("info").setAttribute("class", "info");
                document.getElementById("info").innerHTML = info;

             //Attempting to input results into collection
                MovieSearch._collection.insert({
                    title: data['Search'][i]['Title'],
                    year: data['Search'][i]['Year'],
                    imdb: data['Search'][i]['imdbID'],
                });
                        
            }
             var s = document.createElement("input");
             s.setAttribute("type", "submit")
             s.setAttribute("value", "Request Movie!")
             s.setAttribute("class", "btn btn-primary");
             document.getElementById("results").appendChild(s);
             document.getElementById('overview').scrollIntoView({block: "end", behavior: "smooth"});
            })
            .fail(function() {
                var mg = '<p>Hmmm something went wrong with your search...<a href="javascript:document.getElementById(\'search\').focus()" class="alert-link">try again in a few moments!</a></p>';
                document.getElementById("info").setAttribute("class", "alert alert-danger");
                document.getElementById("info").innerHTML = mg;
        });
        })();
return false;
}})<commit_msg>Moved to using local collection, code cleanup<commit_after>Template.search.events({
    'submit form': function (event) {
        Session.set('searchingresults', true);
        Session.set('resultsloaded', false);
        document.getElementById("info").innerHTML = "";
        document.getElementById("info").setAttribute("class", "");
 
        var url = "http://www.omdbapi.com/?type=movie&s=" + document.getElementById("search").value;
        
        (function () {
            $.getJSON(url)
                .done(function (data) {
                    MovieSearch._collection.remove({});
                    document.getElementById("search").blur();
                
                    try {
                        var len = data['Search'].length;
                    } catch (err) {
                        Session.set('searchingresults', false);
                        document.getElementById("info").setAttribute("class", "alert alert-warning");
                        document.getElementById("info").innerHTML = '<p>Hmm we got no results...<a href="javascript:document.getElementById(\'search\').focus()" class="alert-link">try again!</a></p>';
                        document.getElementById("overview").innerHTML = "";
                        return;
                    }
                
                    for (i = 0; i < data['Search'].length; i++) {
                        MovieSearch._collection.insert({
                            title: data['Search'][i]['Title'],
                            year: data['Search'][i]['Year'],
                            imdb: data['Search'][i]['imdbID']
                        });
                    }
                    Session.set('searchingresults', false);
                    Session.set('resultsloaded', true);
                })
                .fail(function () {
                    Session.set('searchingresults', false);
                    var msg = '<p>Hmmm something went wrong with your search...<a href="javascript:document.getElementById(\'search\').focus()" class="alert-link">try again in a few moments!</a></p>';
                    document.getElementById("info").setAttribute("class", "alert alert-danger");
                    document.getElementById("info").innerHTML = msg;
                });
        }());
        return false;
    }
});
{'fraction_non_alphanumeric': 0.15365853658536585, 'fraction_numerical': 0.0006097560975609756, 'mean_word_length': 1.6801470588235294, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7557752', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1517, 'n_words': 295}