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.*;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
public abstract class PagingIterable implements
Iterable,
IterableWithTotalHits,
IterableWithScores,
IterableWithHistogramResults,
IterableWithTermsResults,
IterableWithGeohashResults,
IterableWithStatisticsResults,
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;
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.
int firstIterableLimit = Math.min(pageSize, limit == null ? Integer.MAX_VALUE : limit.intValue());
this.firstIterable = getPageIterable((int) this.skip, firstIterableLimit, true);
this.isFirstCallToIterator = true;
}
@Override
public GeohashResult getGeohashResults(String name) {
return this.firstIterable.getGeohashResults(name);
}
@Override
public HistogramResult getHistogramResults(String name) {
return this.firstIterable.getHistogramResults(name);
}
@Override
public StatisticsResult getStatisticsResults(String name) {
return this.firstIterable.getStatisticsResults(name);
}
@Override
public TermsResult getTermsResults(String name) {
return this.firstIterable.getTermsResults(name);
}
@Override
public Map