diff --git a/src/Searching.js b/src/Searching.js index 5fc5b31544..1a5c8d7a48 100644 --- a/src/Searching.js +++ b/src/Searching.js @@ -184,18 +184,9 @@ async function localPagination(searchResult) { return result; } -/** - * Combine the local and server search results - */ -function combineResponses(previousSearchResult, localEvents = undefined, serverEvents = undefined) { +function combineEvents(localEvents = undefined, serverEvents = undefined, cachedEvents = undefined) { const response = {}; - if (previousSearchResult.count) { - response.count = previousSearchResult.count; - } else { - response.count = localEvents.count + serverEvents.count; - } - if (localEvents && serverEvents) { response.results = localEvents.results.concat(serverEvents.results).sort(compareEvents); response.highlights = localEvents.highlights.concat(serverEvents.highlights); @@ -207,6 +198,21 @@ function combineResponses(previousSearchResult, localEvents = undefined, serverE response.highlights = serverEvents.highlights; } + return response; +} + +/** + * Combine the local and server search responses + */ +function combineResponses(previousSearchResult, localEvents = undefined, serverEvents = undefined) { + const response = combineEvents(localEvents, serverEvents); + + if (previousSearchResult.count) { + response.count = previousSearchResult.count; + } else { + response.count = localEvents.count + serverEvents.count; + } + if (localEvents) { previousSearchResult.seshatQuery.next_batch = localEvents.next_batch; response.next_batch = localEvents.next_batch;