<commit_before>(function () {
    'use strict';

    define(
        [
            'lodash',
            'knockout',
            'querystring',
            'config/routes',
            'util/container',
            'models/DynamicRecord',
            'models/ListPager',
            'ui/pages/search/SearchType'
        ],
        function (_, ko, qs, routes, container, DynamicRecord, ListPager, SearchType) {
            var RESULTS_MODES = [ 'List', 'Thumbnails', 'Table' ];

            return function (context) {
                var settings = container.resolve('settings.' + context.params.type),
                    selectedSearchType = ko.observable(),
                    submittedQuery = ko.observable(),
                    results = ko.observableArray(),
                    query = qs.parse(window.location.search.replace(/^\?/, '')),
                    doSearch = function (callback) {
                        submittedQuery(this.searchText());
                        results([]);
                        this.loading(true);
                        this.displayResults(false);
                        container.resolve('search.' + context.params.type)(
                            _.zipObject(
                                [ selectedSearchType() ],
                                [ submittedQuery() ]
                            ),
                            function (err, searchServiceResults) {
                                this.loading(false);
                                if (err) {
                                    // TODO Display error
                                    return;
                                }
                                results(_.map(searchServiceResults, function (result) {
                                    return new DynamicRecord(result, this.searchResultFields);
                                }.bind(this)));
                                this.displayResults(true);
                                if (_.isFunction(callback)) {
                                    callback();
                                }
                            }.bind(this)
                        );
                    }.bind(this);

                this.pager = new ListPager(
                    results,
                    query.start ? parseInt(query.start, 10) : undefined,
                    query.size ? parseInt(query.size, 10) : undefined
                );

                this.searchText = ko.observable(query.query || '');
                this.searchTypes = ko.observableArray();
                this.searchResultFields = ko.observableArray();
                this.loading = ko.observable(false);
                this.displayResults = ko.observable(false);
                this.resultsMode = ko.observable(query.mode || 'List');

                this.type = ko.pureComputed(function () {
                    return context.params.type;
                });

                this.submittedQuery = ko.pureComputed(function () {
                    return submittedQuery();
                });

                this.heading = ko.pureComputed(function () {
                    return settings.collectionName + ' Search';
                });

                this.placeholder = ko.pureComputed(function () {
                    return selectedSearchType() ?
                        _.find(this.searchTypes(), { key: selectedSearchType() }).placeholder :
                        'Enter your search terms...';
                }.bind(this));

                this.hasResults = ko.pureComputed(function () {
                    return results().length > 0;
                });

                this.availableResultsModes = ko.pureComputed(function () {
                    return RESULTS_MODES;
                });

                this.resultsModeClassName = ko.pureComputed(function () {
                    return this.resultsMode().toLowerCase();
                }.bind(this));<commit_msg>Fix class name generator.<commit_after>(function () {
    'use strict';

    define(
        [
            'lodash',
            'knockout',
            'querystring',
            'config/routes',
            'util/container',
            'models/DynamicRecord',
            'models/ListPager',
            'ui/pages/search/SearchType'
        ],
        function (_, ko, qs, routes, container, DynamicRecord, ListPager, SearchType) {
            var RESULTS_MODES = [ 'List', 'Thumbnails', 'Table' ];

            return function (context) {
                var settings = container.resolve('settings.' + context.params.type),
                    selectedSearchType = ko.observable(),
                    submittedQuery = ko.observable(),
                    results = ko.observableArray(),
                    query = qs.parse(window.location.search.replace(/^\?/, '')),
                    doSearch = function (callback) {
                        submittedQuery(this.searchText());
                        results([]);
                        this.loading(true);
                        this.displayResults(false);
                        container.resolve('search.' + context.params.type)(
                            _.zipObject(
                                [ selectedSearchType() ],
                                [ submittedQuery() ]
                            ),
                            function (err, searchServiceResults) {
                                this.loading(false);
                                if (err) {
                                    // TODO Display error
                                    return;
                                }
                                results(_.map(searchServiceResults, function (result) {
                                    return new DynamicRecord(result, this.searchResultFields);
                                }.bind(this)));
                                this.displayResults(true);
                                if (_.isFunction(callback)) {
                                    callback();
                                }
                            }.bind(this)
                        );
                    }.bind(this);

                this.pager = new ListPager(
                    results,
                    query.start ? parseInt(query.start, 10) : undefined,
                    query.size ? parseInt(query.size, 10) : undefined
                );

                this.searchText = ko.observable(query.query || '');
                this.searchTypes = ko.observableArray();
                this.searchResultFields = ko.observableArray();
                this.loading = ko.observable(false);
                this.displayResults = ko.observable(false);
                this.resultsMode = ko.observable(query.mode || 'List');

                this.type = ko.pureComputed(function () {
                    return context.params.type;
                });

                this.submittedQuery = ko.pureComputed(function () {
                    return submittedQuery();
                });

                this.heading = ko.pureComputed(function () {
                    return settings.collectionName + ' Search';
                });

                this.placeholder = ko.pureComputed(function () {
                    return selectedSearchType() ?
                        _.find(this.searchTypes(), { key: selectedSearchType() }).placeholder :
                        'Enter your search terms...';
                }.bind(this));

                this.hasResults = ko.pureComputed(function () {
                    return results().length > 0;
                });

                this.availableResultsModes = ko.pureComputed(function () {
                    return RESULTS_MODES;
                });

                this.resultsModeContainerClassName = ko.pureComputed(function () {
                    return 'results-container-' + this.resultsMode().toLowerCase();
                }.bind(this));
{'fraction_non_alphanumeric': 0.10339622641509434, 'fraction_numerical': 0.0012578616352201257, 'mean_word_length': 1.060378336356569, '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': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '513608', 'n_tokens_mistral': 1826, 'n_tokens_neox': 1650, 'n_words': 285}