public VariantSolrIterator(SolrClient solrClient, String collection, SolrQuery solrQuery, VariantSearchToVariantConverter converter) throws IOException, SolrServerException { variantSearchSolrIterator = new VariantSearchSolrIterator(solrClient, collection, solrQuery); this.variantSearchToVariantConverter = converter; }
public long getNumFound() { return variantSearchSolrIterator.getNumFound(); }
@Override public boolean hasNext() { return variantSearchSolrIterator.hasNext(); }
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(); } } }
@Override public Variant next() { count++; return variantSearchToVariantConverter.convertToDataModelType(variantSearchSolrIterator.next()); }
@Override public VariantSearchModel next() { // Sanity check if (hasNext()) { return solrIterator.next(); } else { throw new NoSuchElementException(); } }
/** * Return a Solr variant iterator to retrieve VariantSearchModel objects from a Solr core/collection * according a given query. * * @param collection Collection name * @param query Query * @param queryOptions Query options * @return Solr VariantSearch iterator * @throws VariantSearchException VariantSearchException */ public VariantSearchSolrIterator nativeIterator(String collection, Query query, QueryOptions queryOptions) throws VariantSearchException { try { SolrQuery solrQuery = solrQueryParser.parse(query, queryOptions); return new VariantSearchSolrIterator(solrManager.getSolrClient(), collection, solrQuery); } catch (SolrServerException e) { throw new VariantSearchException("Error getting variant iterator (native)", e); } }
protected Iterator<String> variantIdIteratorFromSearch(Query query, int limit, int skip, AtomicLong numTotalResults) throws StorageEngineException { Iterator<String> variantsIterator; QueryOptions queryOptions = new QueryOptions() .append(QueryOptions.LIMIT, limit) .append(QueryOptions.SKIP, skip) .append(QueryOptions.INCLUDE, VariantField.ID.fieldName()); try { // Do not iterate for small queries if (limit < 10000) { VariantQueryResult<VariantSearchModel> nativeResult = getVariantSearchManager().nativeQuery(dbName, query, queryOptions); if (numTotalResults != null) { numTotalResults.set(nativeResult.getNumTotalResults()); } variantsIterator = nativeResult.getResult() .stream() .map(VariantSearchModel::getId) .iterator(); } else { VariantSearchSolrIterator nativeIterator = getVariantSearchManager().nativeIterator(dbName, query, queryOptions); if (numTotalResults != null) { numTotalResults.set(nativeIterator.getNumFound()); } variantsIterator = Iterators.transform(nativeIterator, VariantSearchModel::getId); } } catch (VariantSearchException | IOException e) { throw new VariantQueryException("Error querying " + VariantSearchManager.SEARCH_ENGINE_ID, e); } return variantsIterator; }
public long getNumFound() { // Sanity check if (solrResponse == null) { hasNext(); } return solrResponse == null ? 0 : solrResponse.getResults().getNumFound(); } }