@Override public boolean hasNext() { return variantSearchSolrIterator.hasNext(); }
@Override public VariantSearchModel next() { // Sanity check if (hasNext()) { return solrIterator.next(); } else { throw new NoSuchElementException(); } }
public long getNumFound() { // Sanity check if (solrResponse == null) { hasNext(); } return solrResponse == null ? 0 : solrResponse.getResults().getNumFound(); } }
public VariantSearchSolrIterator(SolrClient solrClient, String collection, SolrQuery solrQuery) throws SolrServerException { this.solrClient = solrClient; this.collection = collection; this.solrQuery = solrQuery; // Make sure that query is sorted this.solrQuery.setSort(SolrQuery.SortClause.asc("id")); // This is the limit of the user, or the default limit if it is not passed this.remaining = (solrQuery.getRows() == null || solrQuery.getRows() < 0) ? Integer.MAX_VALUE : solrQuery.getRows(); // We the set cursor at the beginning this.cursorMark = CursorMarkParams.CURSOR_MARK_START; // We create an empty iterator, this will return false in the first hasNext call this.solrIterator = Collections.emptyIterator(); // Current Solr iterator (aka cursorMarks) implementation does not support skip. // A simple solution is to waste these records and remove the Start from the solrQuery if (solrQuery.getStart() != null && solrQuery.getStart() >= 0) { // Do not change the order or position of the next two lines of code Integer skip = solrQuery.getStart(); // We need to increment remaining with skip to allow the decrement in the hasNext method this.remaining = (this.remaining < Integer.MAX_VALUE - skip) ? this.remaining + skip : Integer.MAX_VALUE; solrQuery.setStart(null); for (int i = 0; i < skip && hasNext(); i++) { next(); } } }