Example usage for org.apache.solr.client.solrj SolrClient deleteById

List of usage examples for org.apache.solr.client.solrj SolrClient deleteById

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj SolrClient deleteById.

Prototype

public UpdateResponse deleteById(List<String> ids) throws SolrServerException, IOException 

Source Link

Document

Deletes a list of documents by unique ID.

Usage

From source file:com.frank.search.solr.core.SolrTemplate.java

License:Apache License

@Override
public UpdateResponse deleteById(final String id) {
    Assert.notNull(id, "Cannot delete 'null' id.");

    return execute(new SolrCallback<UpdateResponse>() {
        @Override/*from  ww w  .  ja  v a  2 s.c  om*/
        public UpdateResponse doInSolr(SolrClient solrClient) throws SolrServerException, IOException {
            return solrClient.deleteById(id);
        }
    });
}

From source file:com.frank.search.solr.core.SolrTemplate.java

License:Apache License

@Override
public UpdateResponse deleteById(Collection<String> ids) {
    Assert.notNull(ids, "Cannot delete 'null' collection.");

    final List<String> toBeDeleted = new ArrayList<String>(ids);
    return execute(new SolrCallback<UpdateResponse>() {
        @Override// ww  w  .ja  v a 2  s . c o m
        public UpdateResponse doInSolr(SolrClient solrClient) throws SolrServerException, IOException {
            return solrClient.deleteById(toBeDeleted);
        }
    });
}

From source file:com.headwire.aemsolrsearch.geometrixx.listeners.SolrGeometrixxPageListener.java

License:Apache License

protected void removePage(String id, SolrClient solr) {
    try {/*w w  w .  ja  v a  2  s .  c  o  m*/
        LOG.info("Removing page " + id);
        solr.deleteById(id);
        solr.commit();
    } catch (Exception e) {
        LOG.error("Failure to remove page " + id, e);
    }
}

From source file:net.hasor.search.server.rsf.service.SorlDumpService.java

License:Apache License

private UpdateSearchResult deleteByIDs(final List<String> ids, final Integer commitWithinMs) {
    if (ids == null || ids.isEmpty()) {
        UpdateSearchResult result = new UpdateSearchResult();
        result.setSuccess(false);/*from   ww w.  ja v  a 2  s.c om*/
        result.setMessage("ids is empty or null.");
        LoggerHelper.logWarn("deleteByIDs failure, %s", result);
        return result;
    }
    //
    return this.doExecute(new ExecuteService() {
        @Override
        public UpdateResponse doExecute(SolrClient solrClient) throws Throwable {
            if (commitWithinMs == null) {
                return solrClient.deleteById(ids);
            } else {
                return solrClient.deleteById(ids, commitWithinMs.intValue());
            }
        }
    });
}

From source file:net.yacy.cora.federate.solr.instance.ServerShard.java

License:Open Source License

/**
 * Deletes a single document by unique ID
 * @param id  the ID of the document to delete
 * @throws IOException If there is a low-level I/O error.
 */// w w w .j a v  a  2s.  c  om
@Override
public UpdateResponse deleteById(String id) throws SolrServerException, IOException {
    if (!this.writeEnabled)
        return _dummyOKResponse;
    UpdateResponse ur = null;
    for (SolrClient s : this.shards.server4read())
        ur = s.deleteById(id);
    return ur;
}

From source file:net.yacy.cora.federate.solr.instance.ServerShard.java

License:Open Source License

/**
 * Deletes a list of documents by unique ID
 * @param ids  the list of document IDs to delete 
 * @throws IOException If there is a low-level I/O error.
 *///w  w  w  .  ja  v a  2 s. c  om
@Override
public UpdateResponse deleteById(List<String> ids) throws SolrServerException, IOException {
    if (!this.writeEnabled)
        return _dummyOKResponse;
    UpdateResponse ur = null;
    for (SolrClient s : this.shards.server4read())
        ur = s.deleteById(ids);
    return ur;
}

From source file:org.codice.ddf.persistence.internal.PersistentStoreImpl.java

License:Open Source License

@Override
public int delete(String type, String cql) throws PersistenceException {
    List<Map<String, Object>> itemsToDelete = this.get(type, cql);
    SolrClient solrClient = getSolrClient(type);
    if (solrClient == null) {
        throw new PersistenceException("Unable to create Solr client.");
    }/*from  ww  w  . j a  v a  2  s. c  o m*/
    List<String> idsToDelete = new ArrayList<>();
    for (Map<String, Object> item : itemsToDelete) {
        String uuid = (String) item.get(PersistentItem.ID);
        if (StringUtils.isNotBlank(uuid)) {
            idsToDelete.add(uuid);
        }
    }

    if (!idsToDelete.isEmpty()) {
        try {
            LOGGER.debug("Deleting {} items by ID", idsToDelete.size());
            solrClient.deleteById(idsToDelete);
        } catch (SolrServerException e) {
            LOGGER.info("SolrServerException while trying to delete items by ID for persistent type {}", type,
                    e);
            doRollback(solrClient, type);
            throw new PersistenceException(
                    "SolrServerException while trying to delete items by ID for persistent type " + type, e);
        } catch (IOException e) {
            LOGGER.info("IOException while trying to delete items by ID for persistent type {}", type, e);
            doRollback(solrClient, type);
            throw new PersistenceException(
                    "IOException while trying to delete items by ID for persistent type " + type, e);
        } catch (RuntimeException e) {
            LOGGER.info("RuntimeException while trying to delete items by ID for persistent type {}", type, e);
            doRollback(solrClient, type);
            throw new PersistenceException(
                    "RuntimeException while trying to delete items by ID for persistent type " + type, e);
        }
    }

    return idsToDelete.size();
}

From source file:se.uu.ub.cora.solrindex.SolrRecordIndexer.java

License:Open Source License

private void tryToDeleteFromIndex(String type, String id) throws SolrServerException, IOException {
    SolrClient solrClient = solrClientProvider.getSolrClient();
    solrClient.deleteById(type + "_" + id);
    solrClient.commit();//from  w w  w.j  a v a  2  s  . c  o m
}