Merge branch 'hotfix/21.56.9' into master
[gitter.git] / server / serializers / rest / search-results-strategy.js
blob588f1dd9bbba7d0b747c6eba8d3f7c2bbd24d174
1 'use strict';
3 function SearchResultsStrategy(options) {
4 var resultItemStrategy = options.resultItemStrategy;
6 this.preload = function(searchResults) {
7 var items = searchResults
8 .map(function(i) {
9 return i.results;
11 .flatten();
12 return resultItemStrategy.preload(items);
15 this.map = function(item) {
16 var results = item.results;
17 if (item.results === undefined || item.results === null) {
18 results = [].concat(item);
21 return {
22 hasMoreResults: item.hasMoreResults,
23 limit: item.limit,
24 skip: item.skip,
25 results: results.map(function(i) {
26 return resultItemStrategy.map(i);
32 SearchResultsStrategy.prototype = {
33 name: 'SearchResultsStrategy'
36 module.exports = SearchResultsStrategy;