<commit_before>angular.module("seSearch.helper", ["ui.router"]).service("SeSearchHelperService", function($state, $location) {
	"use strict";
	var DEFAULTS = {
		filterFieldName: "filter",
		resultsFieldName: "searchResults"
	};

	var service = this;

	function attachMethods() {
		service.handleSearch = function($scope, sourceFunc, holder, options) {
			var effectiveOptions = _.assign({}, DEFAULTS, options);

			// params should be configured in $state provider!
			function urlToFilter() {
				// if you change this implementation - remove data-ce-undefined-if-empty
				holder[effectiveOptions.filterFieldName] = _.pick($state.params, _.keys($state.current.params));
			}
			function filterToUrl() {
				// if you change this implementation - remove data-ce-undefined-if-empty
				$location.search(_.pick(holder[effectiveOptions.filterFieldName], _.keys($state.current.params)));
			}

			function searchResults(response) {
				var result = {
					loaded: true,
					response: response,
					pages: {
						prev: null,
						next: null,
						all: []
					}
				};

				for(var i = 0; i < response.navigation.count;i += response.navigation.max) {
					result.pages.all.push({from: i});
				}
				result.pages.prev = angular.copy(_.findLast(result.pages.all, function(page) {
					return page.from < response.navigation.from;
				}));
				if (!result.pages.prev) {
					delete result.pages.prev;
				}

				result.pages.next = angular.copy(_.find(result.pages.all, function(page) {
					return page.from > response.navigation.from;
				}));
				if (!result.pages.next) {
					delete result.pages.next;
				}

				return result;
			}
			function fetch(newFilter) {
				filterToUrl();
				if (holder[effectiveOptions.resultsFieldName]) {
					holder[effectiveOptions.resultsFieldName].loaded = false;
				}
				return sourceFunc(newFilter).then(function(response) {
					var result = searchResults(response);
					holder[effectiveOptions.resultsFieldName] = result;<commit_msg>#3 Paging format should be configurable - added option for custom result processing<commit_after>angular.module("seSearch.helper", ["ui.router"]).service("SeSearchHelperService", function($state, $location) {
	"use strict";
	var DEFAULTS = {
		filterFieldName: "filter",
		resultsFieldName: "searchResults",
		resultProcessor: function searchResults(response) {
			var result = {
				loaded: true,
				response: response,
				pages: {
					prev: null,
					next: null,
					all: []
				}
			};

			for(var i = 0; i < response.navigation.count;i += response.navigation.max) {
				result.pages.all.push({from: i});
			}
			result.pages.prev = angular.copy(_.findLast(result.pages.all, function(page) {
				return page.from < response.navigation.from;
			}));
			if (!result.pages.prev) {
				delete result.pages.prev;
			}

			result.pages.next = angular.copy(_.find(result.pages.all, function(page) {
				return page.from > response.navigation.from;
			}));
			if (!result.pages.next) {
				delete result.pages.next;
			}

			return result;
		}
	};

	var service = this;

	function attachMethods() {
		service.handleSearch = function($scope, sourceFunc, holder, options) {
			var effectiveOptions = _.assign({}, DEFAULTS, options);

			// params should be configured in $state provider!
			function urlToFilter() {
				// if you change this implementation - remove data-ce-undefined-if-empty
				holder[effectiveOptions.filterFieldName] = _.pick($state.params, _.keys($state.current.params));
			}
			function filterToUrl() {
				// if you change this implementation - remove data-ce-undefined-if-empty
				$location.search(_.pick(holder[effectiveOptions.filterFieldName], _.keys($state.current.params)));
			}


			function fetch(newFilter) {
				filterToUrl();
				if (holder[effectiveOptions.resultsFieldName]) {
					holder[effectiveOptions.resultsFieldName].loaded = false;
				}
				return sourceFunc(newFilter).then(function(response) {
					var result = effectiveOptions.resultProcessor(response);
					holder[effectiveOptions.resultsFieldName] = result;
{'fraction_non_alphanumeric': 0.13437268002969563, 'fraction_numerical': 0.0007423904974016332, 'mean_word_length': 3.6036446469248293, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5910886', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1175, 'n_words': 241}