<commit_before>angular.module('HNSearch.services', ['algoliasearch', 'ngStorage', 'angular-google-analytics'])

.factory('settings', ['$location', 'algolia', '$localStorage', 'Analytics', function($location, algolia, $localStorage, Analytics) {
    var settingsService = {};

    //default settings
    var storage = $localStorage.$default({
        showThumbnails: true,
        defaultSort: 'byPopularity',
        defaultDateRange: 'last24h',
        style: 'default'
    });

    var _loadSettings = function() {
        var queryParameters = $location.search();
        var defaultDateRange, defaultSort;
        if (queryParameters.q) {
            $location.search('query', queryParameters.q).search('q', null).replace();
            defaultDateRange = 'all';
            defaultSort = 'byPopularity';
        } else {
            defaultDateRange = storage.defaultDateRange;
            defaultSort = storage.defaultSort;
        }
        return {
            dateRange: (queryParameters.dateRange || defaultDateRange),
            defaultDateRange: storage.defaultDateRange,
            type: (queryParameters.type || 'story'),
            sort: (queryParameters.sort || defaultSort),
            defaultSort: storage.defaultSort,
            prefix: (queryParameters.prefix || true),
            page: (parseInt(queryParameters.page, 10) || 0),
            showThumbnails: storage.showThumbnails,
            login: storage.login,
            style: (queryParameters.experimental ? 'experimental' : storage.style),
            dateStart: queryParameters.dateStart,
            dateEnd: queryParameters.dateEnd
        };
    }
    var settings = _loadSettings();

    // Algolia settings
    var algoliaConfig = { appID: 'UJ5WYC0L7X', apiKey: '8ece23f8eb07cd25d40262a1764599b1' }; // FIXME

    settingsService.client = algolia.Client(algoliaConfig.appID, algoliaConfig.apiKey);
    settingsService.indexSortedByPopularity = settingsService.client.initIndex('Item_production');
    settingsService.indexSortedByPopularityOrdered = settingsService.client.initIndex('Item_production_ordered');
    settingsService.indexSortedByDate = settingsService.client.initIndex('Item_production_sort_date');
    settingsService.indexUser = settingsService.client.initIndex('User_production');

    settingsService.reset = function() {
        settings.dateRange = settings.defaultDateRange;
        settings.sort = settings.defaultSort;
        settings.type = 'story';
        settings.page = 0;
    };

    settingsService.get = function() {
        return settings;
    };

    settingsService.reload = function() {
        var s = _loadSettings();
        for (var v in s) {
            settings[v] = s[v];
        }
        return settings;
    }

    settingsService.save = function() {
        $localStorage.showThumbnails = settings.showThumbnails;
        $localStorage.login = settings.login;
        $localStorage.style = settings.style;
        $('body').attr('rel', settings.style);

        if ($localStorage.defaultSort != settings.defaultSort) {
            settings.sort = settings.defaultSort;
        }
        $localStorage.defaultSort = settings.defaultSort;

        if ($localStorage.defaultDateRange != settings.defaultDateRange) {
            settings.dateRange = settings.defaultDateRange;
        }
        $localStorage.defaultDateRange = settings.defaultDateRange;

        // GA
        Analytics.trackEvent('settings', 'style', settings.style);
        Analytics.trackEvent('settings', 'defaultSort', settings.defaultSort);
        Analytics.trackEvent('settings', 'defaultDateRange', settings.defaultDateRange);
    };

    return settingsService;
}])

.factory('search', ['$location', function($location) {
    var queryParameters = $location.search();
    var searchService = {
        query: (queryParameters.query || queryParameters.q || ''),
        params: {
            hitsPerPage: 20,
            minWordSizefor1Typo: 5,
            minWordSizefor2Typos: 9,
            advancedSyntax: true,
            ignorePlurals: true
        }
    };

    //dates
    var last24h = new Date();<commit_msg>Do not ignore plurals. Fix #53<commit_after>angular.module('HNSearch.services', ['algoliasearch', 'ngStorage', 'angular-google-analytics'])

.factory('settings', ['$location', 'algolia', '$localStorage', 'Analytics', function($location, algolia, $localStorage, Analytics) {
    var settingsService = {};

    //default settings
    var storage = $localStorage.$default({
        showThumbnails: true,
        defaultSort: 'byPopularity',
        defaultDateRange: 'last24h',
        style: 'default'
    });

    var _loadSettings = function() {
        var queryParameters = $location.search();
        var defaultDateRange, defaultSort;
        if (queryParameters.q) {
            $location.search('query', queryParameters.q).search('q', null).replace();
            defaultDateRange = 'all';
            defaultSort = 'byPopularity';
        } else {
            defaultDateRange = storage.defaultDateRange;
            defaultSort = storage.defaultSort;
        }
        return {
            dateRange: (queryParameters.dateRange || defaultDateRange),
            defaultDateRange: storage.defaultDateRange,
            type: (queryParameters.type || 'story'),
            sort: (queryParameters.sort || defaultSort),
            defaultSort: storage.defaultSort,
            prefix: (queryParameters.prefix || true),
            page: (parseInt(queryParameters.page, 10) || 0),
            showThumbnails: storage.showThumbnails,
            login: storage.login,
            style: (queryParameters.experimental ? 'experimental' : storage.style),
            dateStart: queryParameters.dateStart,
            dateEnd: queryParameters.dateEnd
        };
    }
    var settings = _loadSettings();

    // Algolia settings
    var algoliaConfig = { appID: 'UJ5WYC0L7X', apiKey: '8ece23f8eb07cd25d40262a1764599b1' }; // FIXME

    settingsService.client = algolia.Client(algoliaConfig.appID, algoliaConfig.apiKey);
    settingsService.indexSortedByPopularity = settingsService.client.initIndex('Item_production');
    settingsService.indexSortedByPopularityOrdered = settingsService.client.initIndex('Item_production_ordered');
    settingsService.indexSortedByDate = settingsService.client.initIndex('Item_production_sort_date');
    settingsService.indexUser = settingsService.client.initIndex('User_production');

    settingsService.reset = function() {
        settings.dateRange = settings.defaultDateRange;
        settings.sort = settings.defaultSort;
        settings.type = 'story';
        settings.page = 0;
    };

    settingsService.get = function() {
        return settings;
    };

    settingsService.reload = function() {
        var s = _loadSettings();
        for (var v in s) {
            settings[v] = s[v];
        }
        return settings;
    }

    settingsService.save = function() {
        $localStorage.showThumbnails = settings.showThumbnails;
        $localStorage.login = settings.login;
        $localStorage.style = settings.style;
        $('body').attr('rel', settings.style);

        if ($localStorage.defaultSort != settings.defaultSort) {
            settings.sort = settings.defaultSort;
        }
        $localStorage.defaultSort = settings.defaultSort;

        if ($localStorage.defaultDateRange != settings.defaultDateRange) {
            settings.dateRange = settings.defaultDateRange;
        }
        $localStorage.defaultDateRange = settings.defaultDateRange;

        // GA
        Analytics.trackEvent('settings', 'style', settings.style);
        Analytics.trackEvent('settings', 'defaultSort', settings.defaultSort);
        Analytics.trackEvent('settings', 'defaultDateRange', settings.defaultDateRange);
    };

    return settingsService;
}])

.factory('search', ['$location', function($location) {
    var queryParameters = $location.search();
    var searchService = {
        query: (queryParameters.query || queryParameters.q || ''),
        params: {
            hitsPerPage: 20,
            minWordSizefor1Typo: 5,
            minWordSizefor2Typos: 9,
            advancedSyntax: true,
            ignorePlurals: false
        }
    };

    //dates
    var last24h = new Date();
{'fraction_non_alphanumeric': 0.11609944484672942, 'fraction_numerical': 0.00941346850108617, 'mean_word_length': 2.768531150522965, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4803672', 'n_tokens_mistral': 2265, 'n_tokens_neox': 2202, 'n_words': 400}