Searching: Split out more logic that combines the events.

This commit is contained in:
Damir Jelić 2020-06-03 14:30:21 +02:00
parent b6198e0ab9
commit c2e0e10553

View file

@ -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;