<commit_before>/*global MoviesMVC */
'use strict';

MoviesMVC.module('MovieList', function (MovieList, App, Backbone, Marionette, $, _) {

  // MovieList Controller (Mediator)
  // ------------------------------
  //
  // Control the workflow and logic that exists at the application
  // level, above the implementation detail of views and models
  MovieList.Controller = Marionette.Controller.extend({
    // Start the app by showing the appropriate views
    initialize: function () {
      // global events
      MoviesMVC.vent.on('query_received', this.onQueryReceived.bind(this));
      MoviesMVC.vent.on('results_received', this.renderSearchResults.bind(this));

      // Collections
      MoviesMVC.searchCollection = new MovieList.Models.SearchCollection();
      MoviesMVC.moviesCollection = new MovieList.Models.MovieCollection();

      this.elastiSearcher = new MovieList.ElasticSearcher();
      
      // LatestSearchesView
      this.latestSearchesView = new MovieList.Views.LatestSearchesView({
        collection: MoviesMVC.searchCollection
      });
      $('.rightMenu').prepend(this.latestSearchesView.render().el);

      // get DATA
      MoviesMVC.searchCollection.fetch({reset: true});

      // set current search
      if(MoviesMVC.searchCollection.length > 0){
        MoviesMVC.currentSearchModel = MoviesMVC.searchCollection.last();
      }
    },


    ////////////////
    // global events
    ////////////////
    onQueryReceived: function(query) {
      var router = MoviesMVC.router;
      router.navigate('movies/search/' + query, {trigger: true});
    },

    renderSearchResults: function(searchModel) {
      // set current search<commit_msg>when searching empty query, search all<commit_after>/*global MoviesMVC */
'use strict';

MoviesMVC.module('MovieList', function (MovieList, App, Backbone, Marionette, $, _) {

  // MovieList Controller (Mediator)
  // ------------------------------
  //
  // Control the workflow and logic that exists at the application
  // level, above the implementation detail of views and models
  MovieList.Controller = Marionette.Controller.extend({
    // Start the app by showing the appropriate views
    initialize: function () {
      // global events
      MoviesMVC.vent.on('query_received', this.onQueryReceived.bind(this));
      MoviesMVC.vent.on('results_received', this.renderSearchResults.bind(this));

      // Collections
      MoviesMVC.searchCollection = new MovieList.Models.SearchCollection();
      MoviesMVC.moviesCollection = new MovieList.Models.MovieCollection();

      this.elastiSearcher = new MovieList.ElasticSearcher();
      
      // LatestSearchesView
      this.latestSearchesView = new MovieList.Views.LatestSearchesView({
        collection: MoviesMVC.searchCollection
      });
      $('.rightMenu').prepend(this.latestSearchesView.render().el);

      // get DATA
      MoviesMVC.searchCollection.fetch({reset: true});

      // set current search
      if(MoviesMVC.searchCollection.length > 0){
        MoviesMVC.currentSearchModel = MoviesMVC.searchCollection.last();
      }
    },


    ////////////////
    // global events
    ////////////////
    onQueryReceived: function(query) {
      if(query === ''){
        query = '*:*';
      }
      var router = MoviesMVC.router;
      router.navigate('movies/search/' + query, {trigger: true});
    },

    renderSearchResults: function(searchModel) {
      // set current search
{'fraction_non_alphanumeric': 0.14729808251016852, 'fraction_numerical': 0.0005810575246949448, 'mean_word_length': 2.658873538788523, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2867973', 'n_tokens_mistral': 978, 'n_tokens_neox': 939, 'n_words': 194}