# Source: themes/ess-dive/views/DataCatalogView.js

    /*global define */
    define(['jquery',
    				'jqueryui',
    				'underscore',
    				'backbone',
    				'bioportal',
    				'collections/SolrResults',
    				'models/Search',
    				'models/Stats',
    	            'views/BaseDataCatalogView',
    				'views/SearchResultView',
    				'text!templates/search.html',
    				'text!templates/statCounts.html',
    				'text!templates/pager.html',
    				'text!templates/mainContent.html',
    				'text!templates/currentFilter.html',
    				'text!templates/loading.html',
    				'gmaps',
    				'nGeohash'
    				],
    	function($, $ui, _, Backbone, Bioportal, SearchResults, SearchModel, StatsModel, BaseDataCatalogView,
    			 SearchResultView, CatalogTemplate, CountTemplate, PagerTemplate, MainContentTemplate, CurrentFilterTemplate, LoadingTemplate, gmaps, nGeohash) {
    	'use strict';

    	var DataCatalogView = BaseDataCatalogView.extend({

    		/**
    		 * getResults gets all the current search filters from the searchModel, creates a Solr query, and runs that query.
    		 */
    		getResults: function (page) {

    			//Set the sort order based on user choice
    			var sortOrder = this.searchModel.get('sortOrder');
    			this.searchResults.setSort(sortOrder);

    			//Specify which fields to retrieve
    			var fields = "id,seriesId,title,origin,authorLastName,pubDate,dateUploaded,abstract,resourceMap,beginDate,endDate,read_count_i,geohash_9,datasource,isPublic,project";
    			if(gmaps){
    				fields += ",northBoundCoord,southBoundCoord,eastBoundCoord,westBoundCoord";
    			}
    			this.searchResults.setfields(fields);

    			//Get the query
    			var query = this.searchModel.getQuery();

    			//Specify which facets to retrieve
    			if(gmaps && this.map){ //If we have Google Maps enabled
    				var geohashLevel = "geohash_" + MetacatUI.mapModel.determineGeohashLevel(this.map.zoom);
    				this.searchResults.facet.push(geohashLevel);
    			}

    			//Run the query
    			this.searchResults.setQuery(query);

    			//Get the page number
    			if(this.isSubView)
    				var page = 0;
    			else{
    				var page = MetacatUI.appModel.get("page");
    				if (page == null) {
    					page = 0;
    				}
    			}
    			this.searchResults.start = page * this.searchResults.rows;

    			//Show or hide the reset filters button
    			if(this.searchModel.filterCount() > 0){
    				this.showClearButton();
    			}
    			else{
    				this.hideClearButton();
    			}

    			// go to the page
    			this.showPage(page);

    			// don't want to follow links
    			return false;
    		}

    	});
    	return DataCatalogView;
    });