org.vertexium.elasticsearch.utils.PagingIterable Maven / Gradle / Ivy
package org.vertexium.elasticsearch.utils;
import org.vertexium.VertexiumException;
import org.vertexium.elasticsearch.ElasticSearchGraphQueryIterable;
import org.vertexium.query.AggregationResult;
import org.vertexium.query.IterableWithScores;
import org.vertexium.query.IterableWithTotalHits;
import org.vertexium.query.QueryResultsIterable;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
public abstract class PagingIterable implements
Iterable,
IterableWithTotalHits,
IterableWithScores,
QueryResultsIterable {
private final long skip;
private final long limit;
private boolean isFirstCallToIterator;
private final ElasticSearchGraphQueryIterable firstIterable;
private final int pageSize;
public PagingIterable(long skip, Long limit, int pageSize) {
this.skip = skip;
this.limit = limit == null ? Long.MAX_VALUE : limit;
this.pageSize = pageSize;
// This is a bit of a hack. Because the underlying iterable is the iterable with geohash results, histogram results, etc.
// we need to grab the first iterable to get the results out.
long firstIterableLimit = Math.min(pageSize, this.limit);
this.firstIterable = getPageIterable((int) this.skip, (int)firstIterableLimit, true);
this.isFirstCallToIterator = true;
}
@Override
public Map