<commit_before>/*
 * Copyright 2014-2017 Hewlett Packard Enterprise Development Company, L.P.
 * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
 */

define([
    'underscore',
    'jquery',
    'backbone',
    'js-whatever/js/base-page',
    'find/app/configuration',
    'find/app/model/dates-filter-model',
    'find/app/model/geography-model',
    './search/document-renderer',
    'parametric-refinement/selected-values-collection',
    'find/app/model/documents-collection',
    'find/app/page/search/input-view',
    'find/app/page/search/input-view-query-text-strategy',
    'find/app/page/search/tabbed-search-view',
    'find/app/util/merge-collection',
    'find/app/model/saved-searches/saved-search-model',
    'find/app/page/search/query-middle-column-header-view',
    'find/app/model/min-score-model',
    'find/app/model/query-text-model',
    'find/app/model/document-model',
    'find/app/page/search/document-content-view',
    'find/app/page/search/document/document-detail-content-view',
    'find/app/page/search/results/query-strategy',
    'find/app/page/search/related-concepts/related-concepts-click-handlers',
    'find/app/util/database-name-resolver',
    'find/app/util/saved-query-result-poller',
    'find/app/util/events',
    'find/app/router',
    'find/app/vent',
    'i18n!find/nls/bundle',
    'text!find/templates/app/page/find-search.html'
], function(_, $, Backbone, BasePage, config, DatesFilterModel, GeographyModel, DocumentRenderer, SelectedParametricValuesCollection,
            DocumentsCollection, InputView, queryTextStrategy, TabbedSearchView, MergeCollection,
            SavedSearchModel, QueryMiddleColumnHeaderView, MinScoreModel, QueryTextModel, DocumentModel,
            DocumentContentView, DocumentDetailContentView, queryStrategy, relatedConceptsClickHandlers, databaseNameResolver,
            SavedQueryResultPoller, events, router, vent, i18n, template) {
    'use strict';

    const reducedClasses = 'reverse-animated-container col-md-offset-1 ' +
        'col-lg-offset-2 col-xs-12 col-sm-12 col-md-10 col-lg-8';
    const expandedClasses = 'animated-container col-sm-offset-0 col-md-offset-3 ' +
        'col-lg-offset-3 col-md-6 col-lg-6 col-xs-9 col-sm-9';

    const html = _.template(template)({i18n: i18n});

    const configuration = config();
    const defaultDeselectedDatabases = _.map(configuration && configuration.uiCustomization &&
        configuration.uiCustomization.defaultDeselectedDatabases || []);

    const dbSelectMap = _.reduce(defaultDeselectedDatabases, function(acc, val){
        acc[val.toLowerCase()] = false;
        return acc;
    }, {})

    function selectInitialIndexes(indexesCollection) {
        const privateIndexes = indexesCollection.reject({domain: 'PUBLIC_INDEXES'});
        const selectedIndexes = privateIndexes.length > 0
            ? privateIndexes
            : indexesCollection.models;

        return _.map(selectedIndexes, function(indexModel) {
            return indexModel.pick('domain', 'name');
        });
    }

    function selectFilteredInitialIndexes(indexesCollection) {
        const active = selectInitialIndexes(indexesCollection);

        return defaultDeselectedDatabases.length ? _.filter(active, function(index){
            return !_.has(dbSelectMap, index.name.toLowerCase());
        }) : active;
    }

    return BasePage.extend({
        className: 'search-page',
        template: _.template(template),

        // Callbacks to bind the search bar to the active tab; will be removed and added as the user changes tabs
        searchChangeCallback: null,
        queryTextCallback: null,

        // May be overridden
        QueryMiddleColumnHeaderView: QueryMiddleColumnHeaderView,
        serviceViewOptions: _.constant({}),

        // Abstract
        IndexesCollection: null,
        ServiceView: null,
        SuggestView: null,
        documentDetailOptions: null,
        suggestOptions: null,
        QueryLeftSideView: null,

        initialize: function(options) {
            this.configuration = configuration;
            this.mmapTab = options.mmapTab;
            const optionalViews = [{
                enabled: !this.configuration.hasBiRole,
                selector: '.input-view-container',
                construct: function() {
                    // Model representing search bar text
                    this.searchModel = new QueryTextModel();

                    this.listenTo(this.searchModel, 'change', function() {
                        // Bind search model to routing
                        vent.navigate(this.generateURL(), {trigger: false});

                        if(this.searchModel.get('inputText')) {
                            this.toggleExpandedState(true);

                            // Create a tab if the user has run a search but has no open tabs
                            if(this.selectedTabModel.get('selectedSearchCid') === null) {<commit_msg>(CORE-4320) Remove optimization so that test passes.<commit_after>/*
 * Copyright 2014-2017 Hewlett Packard Enterprise Development Company, L.P.
 * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
 */

define([
    'underscore',
    'jquery',
    'backbone',
    'js-whatever/js/base-page',
    'find/app/configuration',
    'find/app/model/dates-filter-model',
    'find/app/model/geography-model',
    './search/document-renderer',
    'parametric-refinement/selected-values-collection',
    'find/app/model/documents-collection',
    'find/app/page/search/input-view',
    'find/app/page/search/input-view-query-text-strategy',
    'find/app/page/search/tabbed-search-view',
    'find/app/util/merge-collection',
    'find/app/model/saved-searches/saved-search-model',
    'find/app/page/search/query-middle-column-header-view',
    'find/app/model/min-score-model',
    'find/app/model/query-text-model',
    'find/app/model/document-model',
    'find/app/page/search/document-content-view',
    'find/app/page/search/document/document-detail-content-view',
    'find/app/page/search/results/query-strategy',
    'find/app/page/search/related-concepts/related-concepts-click-handlers',
    'find/app/util/database-name-resolver',
    'find/app/util/saved-query-result-poller',
    'find/app/util/events',
    'find/app/router',
    'find/app/vent',
    'i18n!find/nls/bundle',
    'text!find/templates/app/page/find-search.html'
], function(_, $, Backbone, BasePage, config, DatesFilterModel, GeographyModel, DocumentRenderer, SelectedParametricValuesCollection,
            DocumentsCollection, InputView, queryTextStrategy, TabbedSearchView, MergeCollection,
            SavedSearchModel, QueryMiddleColumnHeaderView, MinScoreModel, QueryTextModel, DocumentModel,
            DocumentContentView, DocumentDetailContentView, queryStrategy, relatedConceptsClickHandlers, databaseNameResolver,
            SavedQueryResultPoller, events, router, vent, i18n, template) {
    'use strict';

    const reducedClasses = 'reverse-animated-container col-md-offset-1 ' +
        'col-lg-offset-2 col-xs-12 col-sm-12 col-md-10 col-lg-8';
    const expandedClasses = 'animated-container col-sm-offset-0 col-md-offset-3 ' +
        'col-lg-offset-3 col-md-6 col-lg-6 col-xs-9 col-sm-9';

    const html = _.template(template)({i18n: i18n});

    const configuration = config();
    const defaultDeselectedDatabases = _.map(configuration && configuration.uiCustomization &&
        configuration.uiCustomization.defaultDeselectedDatabases || []);

    const dbSelectMap = _.reduce(defaultDeselectedDatabases, function(acc, val){
        acc[val.toLowerCase()] = false;
        return acc;
    }, {})

    function selectInitialIndexes(indexesCollection) {
        const privateIndexes = indexesCollection.reject({domain: 'PUBLIC_INDEXES'});
        const selectedIndexes = privateIndexes.length > 0
            ? privateIndexes
            : indexesCollection.models;

        return _.map(selectedIndexes, function(indexModel) {
            return indexModel.pick('domain', 'name');
        });
    }

    function selectFilteredInitialIndexes(indexesCollection) {
        const active = selectInitialIndexes(indexesCollection);

        return defaultDeselectedDatabases.length ? _.filter(active, function(index){
            return !_.has(dbSelectMap, index.name.toLowerCase());
        }) : active;
    }

    return BasePage.extend({
        className: 'search-page',
        template: _.template(template),

        // Callbacks to bind the search bar to the active tab; will be removed and added as the user changes tabs
        searchChangeCallback: null,
        queryTextCallback: null,

        // May be overridden
        QueryMiddleColumnHeaderView: QueryMiddleColumnHeaderView,
        serviceViewOptions: _.constant({}),

        // Abstract
        IndexesCollection: null,
        ServiceView: null,
        SuggestView: null,
        documentDetailOptions: null,
        suggestOptions: null,
        QueryLeftSideView: null,

        initialize: function(options) {
            this.configuration = config();
            this.mmapTab = options.mmapTab;
            const optionalViews = [{
                enabled: !this.configuration.hasBiRole,
                selector: '.input-view-container',
                construct: function() {
                    // Model representing search bar text
                    this.searchModel = new QueryTextModel();

                    this.listenTo(this.searchModel, 'change', function() {
                        // Bind search model to routing
                        vent.navigate(this.generateURL(), {trigger: false});

                        if(this.searchModel.get('inputText')) {
                            this.toggleExpandedState(true);

                            // Create a tab if the user has run a search but has no open tabs
                            if(this.selectedTabModel.get('selectedSearchCid') === null) {
{'fraction_non_alphanumeric': 0.1166302404132724, 'fraction_numerical': 0.006954102920723227, 'mean_word_length': 2.7051895472948106, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7590174', 'n_tokens_mistral': 2865, 'n_tokens_neox': 2756, 'n_words': 532}