Example usage for org.apache.solr.client.solrj.response UpdateResponse getResponse

List of usage examples for org.apache.solr.client.solrj.response UpdateResponse getResponse

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.response UpdateResponse getResponse.

Prototype

@Override
    public NamedList<Object> getResponse() 

Source Link

Usage

From source file:at.kc.tugraz.ss.service.solr.impl.SSSolrImpl.java

License:Apache License

@Override
public void solrRemoveDocsAll(final SSServPar parA) throws Exception {

    try {//from   w w  w. jav a 2 s  . c om

        NamedList<Object> nl;
        UpdateResponse ur;

        SSLogU.info("starting to remove all documents from index.");

        ur = solrUpdater.deleteByQuery("*:*");
        solrUpdater.commit();

        nl = ur.getResponse();

        SSLogU.info("removed all documents from index.");
    } catch (Exception error) {
        SSServErrReg.regErrThrow(error);
    }
}

From source file:be.ibridge.kettle.trans.step.solrin.SolrIn.java

License:LGPL

private Value callHttpService(Row row) throws KettleException {

    UpdateResponse upres;

    try {//from   ww w . j  a v a  2  s .  c o  m

        SolrInputDocument doc = new SolrInputDocument();
        logDetailed("Connecting to : [" + url + "]");

        for (int i = 0; i < data.argnrs.length; i++) {
            doc.addField(//meta.getArgumentField()[i],
                    meta.getArgumentParameter()[i], row.getValue(data.argnrs[i]).toString(false));

        }

        upres = server.add(doc);
        // logDetailed("ADD:" + upres.getResponse());
        if (upres == null) {
            throw new KettleException("Unable add document URL :" + url + ": null response");
        }
        if (upres == null && (upres.getStatus() != 0)) {
            throw new KettleException("Unable add document URL :" + url + ":" + upres.getResponse());
        }
        rowCount++;
        if (rowCount == 1000) {
            logDetailed("Commit ever 1000 records (hard coded)");
            server.commit();
            rowCount = 0;
        }

    }

    catch (Exception e)

    {
        throw new KettleException("Unable to get result from specified URL :" + url, e);
    }

    return new Value("0");
}

From source file:ddf.catalog.cache.solr.impl.UninitializedSolrClientAdaptorTest.java

License:Open Source License

@Test
public void deleteByQuery() throws Exception {
    UpdateResponse response = uninitializedSolrClientAdaptor.deleteByQuery("test-delete-by-query-string");

    assertThat(response.getElapsedTime(), is(equalTo(0L)));
    assertThat(response.getRequestUrl(), is(equalTo("")));
    assertThat(response.getResponse().size(), is(equalTo(0)));
}

From source file:org.apdplat.platform.log.handler.SolrLogHandler.java

License:Open Source License

/**
 * ?/*from  w  ww .j a  va 2 s . co m*/
 * ???
 * 
 * @param <T> ?
 * @param list ?
 */
public <T extends Model> void index(List<T> list) {
    List<SolrInputDocument> docs = getSolrInputDocuments(list);
    //???
    try {
        LOG.info("???");
        solrServer.add(docs);
        UpdateResponse updateResponse = solrServer.commit();
        int status = updateResponse.getStatus();
        if (status == 0) {
            LOG.info("?Core: " + core + " ?? " + docs.size() + " ");
        } else {
            LOG.info("??status" + status);
        }
        LOG.info("ResponseHeader:\n" + updateResponse.getResponseHeader().toString());
        LOG.info("Response:\n" + updateResponse.getResponse().toString());
        //
        docs.clear();
    } catch (IOException | SolrServerException e) {
        LOG.error("???", e);
    }
}

From source file:org.mycore.solr.index.handlers.content.MCRSolrMCRContentMapIndexHandler.java

License:Open Source License

@Override
public void index() throws IOException, SolrServerException {
    int totalCount = contentMap.size();
    LOGGER.info("Handling " + totalCount + " documents");
    //multithread processing will result in too many http request
    UpdateResponse updateResponse;
    try {//from   w  w w .  j  av  a 2  s  . co  m
        Iterator<SolrInputDocument> documents = MCRSolrInputDocumentFactory.getInstance()
                .getDocuments(contentMap);
        SolrClient solrClient = getSolrClient();
        if (solrClient instanceof ConcurrentUpdateSolrClient) {
            //split up to speed up processing
            splitup(documents);
            return;
        }
        if (LOGGER.isDebugEnabled()) {
            ArrayList<SolrInputDocument> debugList = new ArrayList<>();
            while (documents.hasNext()) {
                debugList.add(documents.next());
            }
            LOGGER.debug("Sending these documents: " + debugList);
            //recreate documents interator;
            documents = debugList.iterator();
        }
        if (solrClient instanceof HttpSolrClient) {
            updateResponse = ((HttpSolrClient) solrClient).add(documents);
        } else {
            ArrayList<SolrInputDocument> docs = new ArrayList<>(totalCount);
            while (documents.hasNext()) {
                docs.add(documents.next());
            }
            updateResponse = solrClient.add(docs);
        }
    } catch (Throwable e) {
        LOGGER.warn("Error while indexing document collection. Split and retry.", e);
        splitup();
        return;
    }
    if (updateResponse.getStatus() != 0) {
        LOGGER.error(
                "Error while indexing document collection. Split and retry: " + updateResponse.getResponse());
        splitup();
    } else {
        LOGGER.info("Sending " + totalCount + " documents was successful in " + updateResponse.getElapsedTime()
                + " ms.");
    }

}

From source file:org.mycore.solr.index.handlers.document.MCRSolrInputDocumentsHandler.java

License:Open Source License

@Override
public void index() throws IOException, SolrServerException {
    if (documents == null || documents.isEmpty()) {
        LOGGER.warn("No input documents to index.");
        return;//from   www  .j  a v a 2 s .c  o m
    }
    int totalCount = documents.size();
    LOGGER.info("Handling " + totalCount + " documents");
    SolrClient solrClient = getSolrClient();
    if (solrClient instanceof ConcurrentUpdateSolrClient) {
        LOGGER.info("Detected ConcurrentUpdateSolrClient. Split up batch update.");
        splitDocuments();
        //for statistics:
        documents.clear();
        return;
    }
    UpdateResponse updateResponse;
    try {
        UpdateRequest updateRequest = getUpdateRequest(MCRSolrConstants.UPDATE_PATH);
        updateRequest.add(documents);
        updateResponse = updateRequest.process(getSolrClient());
    } catch (Throwable e) {
        LOGGER.warn("Error while indexing document collection. Split and retry.");
        splitDocuments();
        return;
    }
    if (updateResponse.getStatus() != 0) {
        LOGGER.error(
                "Error while indexing document collection. Split and retry: " + updateResponse.getResponse());
        splitDocuments();
    } else {
        LOGGER.info("Sending " + totalCount + " documents was successful in " + updateResponse.getElapsedTime()
                + " ms.");
    }
}

From source file:org.si4t.solr.SolrIndexDispatcher.java

License:Apache License

public String addBinaries(ConcurrentHashMap<String, BinaryIndexData> binaryAdds,
        SolrClientRequest clientRequest)
        throws IOException, SolrServerException, ParserConfigurationException, SAXException {

    SolrServer server = null;/*from ww w  .j a v  a  2  s. c om*/

    server = this.getSolrServer(clientRequest);

    if (server == null) {
        throw new SolrServerException("Solr server not instantiated.");
    }
    StringBuilder rsp = new StringBuilder();
    String rspResponse = " path not found";

    for (Map.Entry<String, BinaryIndexData> entry : binaryAdds.entrySet()) {
        BinaryIndexData data = entry.getValue();

        log.debug("Dispatching binary content to Solr.");

        FileStream fs = this.getBinaryInputStream(data);

        if (fs != null) {

            String id = data.getUniqueIndexId();
            log.info("Indexing binary with Id: " + id + ", and URL Path:" + data.getIndexUrl());
            ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update/extract");

            up.addContentStream(fs);

            up.setParam("literal.id", id);
            up.setParam("literal.publicationid", data.getPublicationItemId());
            up.setParam("literal.pubdate", "NOW");
            up.setParam("literal.url", data.getIndexUrl().replace(" ", "%20"));

            if (!Utils.StringIsNullOrEmpty(data.getFileSize())) {
                up.setParam("literal.fileSize", data.getFileSize());
            }
            if (!Utils.StringIsNullOrEmpty(data.getFileType())) {
                up.setParam("literal.fileType", data.getFileType());
            }
            up.setParam("defaultField", "binary_content");

            UpdateResponse serverrsp;

            serverrsp = up.process(server);
            rsp.append(serverrsp.getResponse());

            log.info("Committing adding binaries.");
            rsp.append("\n");

            serverrsp = server.commit();
            rsp.append(serverrsp.getResponse());

            rspResponse = rsp.toString();
        } else {
            log.error("Could not process binary: " + data.getIndexUrl());
        }
    }
    return ("Adding binaries had the following response: " + rspResponse);
}

From source file:org.si4t.solr.SolrIndexDispatcher.java

License:Apache License

public String addDocuments(DispatcherPackage dispatcherPackage)
        throws ParserConfigurationException, IOException, SAXException, SolrServerException {
    SolrServer server = this.getSolrServer(dispatcherPackage.getRequest());
    if (server == null) {
        throw new SolrServerException("Solr server not instantiated.");
    }//w w  w  . j  a  v  a2  s .  co m
    ArrayList<SolrInputDocument> documents = dispatcherPackage.getDocuments();

    if (documents == null) {
        throw new NullPointerException("Document list is null");
    }

    for (SolrInputDocument d : documents) {
        if (d == null || d.isEmpty()) {
            log.error("Document is null Or empty");
        } else {
            log.info(Utils.RemoveLineBreaks(d.toString()));
            server.add(d);
        }
    }

    UpdateResponse serverrsp = server.commit(true, true);

    return ("Processing " + documents.size() + " documents had the following response: "
            + serverrsp.getResponse());
}

From source file:org.si4t.solr.SolrIndexDispatcher.java

License:Apache License

public String removeFromSolr(Set<String> ids, SolrClientRequest clientRequest)
        throws SolrServerException, IOException, ParserConfigurationException, SAXException {
    SolrServer server = this.getSolrServer(clientRequest);
    if (server == null) {
        throw new SolrServerException("Solr server not instantiated.");
    }// w  w  w.  java2  s.  com
    ArrayList<String> idList = new ArrayList<String>(ids);
    for (String id : idList) {
        log.debug("Removing: " + id);
    }
    server.deleteById(idList);
    server.optimize(true, true);
    UpdateResponse serverrsp = server.commit(true, true);
    return ("Deleting " + ids.size() + " document(s) had the following response: " + serverrsp.getResponse());
}

From source file:uk.co.flax.biosolr.ontology.documents.storage.solr.SolrStorageEngine.java

License:Apache License

@Override
public void storeDocuments(List<Document> documents) throws StorageEngineException {
    if (documents.isEmpty()) {
        LOGGER.debug("storeDocuments() called with empty list - ignoring");
    } else {// w  w w  . j  a  v  a  2 s .  c o  m
        try {
            UpdateResponse response = server.addBeans(documents, config.getCommitWithinMs());
            if (response.getStatus() != STATUS_OK) {
                LOGGER.error("Unexpected response: {}", response.getResponse());
                throw new StorageEngineException("Solr error adding records: " + response);
            }
        } catch (IOException e) {
            LOGGER.error("IO exception when calling server: {}", e.getMessage());
            throw new StorageEngineException(e);
        } catch (SolrServerException e) {
            LOGGER.error("Server exception when storing entries: {}", e.getMessage());
            throw new StorageEngineException(e);
        }
    }
}