Java Code Examples for org.apache.solr.client.solrj.request.UpdateRequest#getDeleteByIdMap()

The following examples show how to use org.apache.solr.client.solrj.request.UpdateRequest#getDeleteByIdMap() . 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: BaseCloudSolrClient.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private static boolean hasInfoToFindLeaders(UpdateRequest updateRequest, String idField) {
  final Map<SolrInputDocument,Map<String,Object>> documents = updateRequest.getDocumentsMap();
  final Map<String,Map<String,Object>> deleteById = updateRequest.getDeleteByIdMap();

  final boolean hasNoDocuments = (documents == null || documents.isEmpty());
  final boolean hasNoDeleteById = (deleteById == null || deleteById.isEmpty());
  if (hasNoDocuments && hasNoDeleteById) {
    // no documents and no delete-by-id, so no info to find leader(s)
    return false;
  }

  if (documents != null) {
    for (final Map.Entry<SolrInputDocument,Map<String,Object>> entry : documents.entrySet()) {
      final SolrInputDocument doc = entry.getKey();
      final Object fieldValue = doc.getFieldValue(idField);
      if (fieldValue == null) {
        // a document with no id field value, so can't find leader for it
        return false;
      }
    }
  }

  return true;
}
 
Example 2
Source File: JavabinLoader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void delete(SolrQueryRequest req, UpdateRequest update, UpdateRequestProcessor processor) throws IOException {
  SolrParams params = update.getParams();
  DeleteUpdateCommand delcmd = new DeleteUpdateCommand(req);
  if(params != null) {
    delcmd.commitWithin = params.getInt(UpdateParams.COMMIT_WITHIN, -1);
  }
  
  if(update.getDeleteByIdMap() != null) {
    Set<Entry<String,Map<String,Object>>> entries = update.getDeleteByIdMap().entrySet();
    for (Entry<String,Map<String,Object>> e : entries) {
      delcmd.id = e.getKey();
      Map<String,Object> map = e.getValue();
      if (map != null) {
        Long version = (Long) map.get("ver");
        if (version != null) {
          delcmd.setVersion(version);
        }
      }
      if (map != null) {
        String route = (String) map.get(ShardParams._ROUTE_);
        if (route != null) {
          delcmd.setRoute(route);
        }
      }
      processor.processDelete(delcmd);
      delcmd.clear();
    }
  }
  
  if(update.getDeleteQuery() != null) {
    for (String s : update.getDeleteQuery()) {
      delcmd.query = s;
      processor.processDelete(delcmd);
    }
  }
}