Java Code Examples for org.apache.solr.client.solrj.response.QueryResponse#getNextCursorMark()

The following examples show how to use org.apache.solr.client.solrj.response.QueryResponse#getNextCursorMark() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestTolerantUpdateProcessorRandomCloud.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/** uses a Cursor to iterate over every doc in the index, recording the 'id_i' value in a BitSet */
private static final BitSet allDocs(final SolrClient c, final int maxDocIdExpected) throws Exception {
  BitSet docs = new BitSet(maxDocIdExpected+1);
  String cursorMark = CURSOR_MARK_START;
  int docsOnThisPage = Integer.MAX_VALUE;
  while (0 < docsOnThisPage) {
    final SolrParams p = params("q","*:*",
                                "rows","100",
                                // note: not numeric, but we don't actual care about the order
                                "sort", "id asc",
                                CURSOR_MARK_PARAM, cursorMark);
    QueryResponse rsp = c.query(p);
    cursorMark = rsp.getNextCursorMark();
    docsOnThisPage = 0;
    for (SolrDocument doc : rsp.getResults()) {
      docsOnThisPage++;
      int id_i = ((Integer)doc.get("id_i")).intValue();
      assertTrue("found id_i bigger then expected "+maxDocIdExpected+": " + id_i,
                 id_i <= maxDocIdExpected);
      docs.set(id_i);
    }
    cursorMark = rsp.getNextCursorMark();
  }
  return docs;
}
 
Example 2
Source File: DeepPagingIterator.java    From SolRDF with Apache License 2.0 5 votes vote down vote up
@Override
public boolean hasNext() {
	try {
		final QueryResponse response = cloud.query(query);
	    
		sentCursorMark = query.get("cursorMark");
		nextCursorMark = response.getNextCursorMark();
		
		page = response.getResults();

		return page.size() > 0;
	} catch (final Exception exception) {
		throw new RuntimeException(exception);
	}
}
 
Example 3
Source File: DeepPagingIterator.java    From SolRDF with Apache License 2.0 5 votes vote down vote up
@Override
public boolean hasNext() {
	try {
		final QueryResponse response = cloud.query(query);
	    
		sentCursorMark = query.get("cursorMark");
		nextCursorMark = response.getNextCursorMark();
		
		page = response.getResults();

		return page.size() > 0;
	} catch (final Exception exception) {
		throw new RuntimeException(exception);
	}
}
 
Example 4
Source File: SolrEntityProcessor.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
protected Iterator<Map<String,Object>> createNextPageIterator(QueryResponse response) {
  return
      new SolrDocumentListCursor(response.getResults(),
          response.getNextCursorMark()) ;
}
 
Example 5
Source File: DistribCursorPagingTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/**
 * Given a QueryResponse returned by SolrServer.query, asserts that the
 * response does include {@link CursorMarkParams#CURSOR_MARK_NEXT} key and returns it
 * @see org.apache.solr.client.solrj.SolrClient#query
 */
private String assertHashNextCursorMark(QueryResponse rsp) {
  String r = rsp.getNextCursorMark();
  assertNotNull(CURSOR_MARK_NEXT+" is null/missing", r);
  return r;
}
 
Example 6
Source File: SolrMetaAlertSearchDao.java    From metron with Apache License 2.0 4 votes vote down vote up
@Override
public SearchResponse getAllMetaAlertsForAlert(String guid) throws InvalidSearchException {
  if (guid == null || guid.trim().isEmpty()) {
    throw new InvalidSearchException("Guid cannot be empty");
  }

  // Searches for all alerts containing the meta alert guid in it's "metalerts" array
  // The query has to match the parentFilter to avoid errors.  Guid must also be explicitly
  // included.
  String activeClause =
      MetaAlertConstants.STATUS_FIELD + ":" + MetaAlertStatus.ACTIVE.getStatusString();
  String guidClause = Constants.GUID + ":" + guid;
  String fullClause = "{!parent which=" + activeClause + "}" + guidClause;
  String metaalertTypeClause = config.getSourceTypeField() + ":" + MetaAlertConstants.METAALERT_TYPE;
  SolrQuery solrQuery = new SolrQuery()
      .setQuery(fullClause)
      .setFields("*", "[child parentFilter=" + metaalertTypeClause + " limit=999]")
      .addSort(Constants.GUID,
          SolrQuery.ORDER.asc); // Just do basic sorting to track where we are

  // Use Solr's Cursors to handle the paging, rather than doing it manually.
  List<SearchResult> allResults = new ArrayList<>();
  try {
    String cursorMark = CursorMarkParams.CURSOR_MARK_START;
    boolean done = false;
    while (!done) {
      solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
      QueryResponse rsp = solrClient.query(METAALERTS_COLLECTION, solrQuery);
      String nextCursorMark = rsp.getNextCursorMark();
      rsp.getResults().stream()
          .map(solrDocument -> SolrUtilities.getSearchResult(solrDocument, null,
                  solrSearchDao.getAccessConfig().getIndexSupplier()))
          .forEachOrdered(allResults::add);
      if (cursorMark.equals(nextCursorMark)) {
        done = true;
      }
      cursorMark = nextCursorMark;
    }
  } catch (IOException | SolrServerException e) {
    throw new InvalidSearchException("Unable to complete search", e);
  }

  SearchResponse searchResponse = new SearchResponse();
  searchResponse.setResults(allResults);
  searchResponse.setTotal(allResults.size());
  return searchResponse;
}