next method

  1. @override
Future<SearchResult?> next()
override

Implementation

@override
Future<SearchResult?> next() async {
  if (fetched >= total!) {
    return null;
  }
  if (request!.size != null) {
    if (request!.from! >= total!) {
      return null;
    }

    return await kuzzle
        .query(KuzzleRequest.clone(request!)
          ..action = searchAction
          ..from = fetched)
        .then((_response) {
      response = _response;

      final result = response!.result as Map<String, dynamic>;

      if (result.containsKey('aggregations')) {
        aggregations = result['aggregations'] as Map<String, dynamic>?;
      }
      if (result.containsKey('hits')) {
        hits = result['hits'] as List<dynamic>?;
        fetched = fetched;
      }

      return buildNextSearchResult(response);
    });
  }

  throw KuzzleError('Unable to retrieve next results from search: '
      'missing from/size params');
}