Search in sources :

Example 41 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project mamute by caelum.

the class SolrQuestionIndex method indexQuestion.

@Override
public void indexQuestion(Question question) {
    try {
        SolrInputDocument doc = toDoc(question);
        server.add(doc);
        server.commit();
        LOGGER.info("Question synced or updated: " + question);
    } catch (IOException | SolrServerException e) {
        throw new IndexException("Could not index Question [" + question.getId() + "]", e);
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Example 42 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project RecordManager2 by moravianlibrary.

the class SolrServerFacadeImpl method indexLazyFulltext.

private void indexLazyFulltext(Collection<SolrInputDocument> documents, int commitWithinMs) throws SolrServerException {
    for (SolrInputDocument document : documents) {
        boolean carryOn = true;
        while (carryOn) {
            try {
                LazyFulltextFieldImpl fulltext = (LazyFulltextFieldImpl) document.getFieldValue(SolrFieldConstants.FULLTEXT_FIELD);
                document.setField(SolrFieldConstants.FULLTEXT_FIELD, fulltext.getContent());
                server.add(document, commitWithinMs);
                exceptionHandler.ok();
                carryOn = false;
            } catch (SolrException | SolrServerException | IOException ex) {
                carryOn = exceptionHandler.handle(ex, Collections.singletonList(document)) == Action.RETRY;
            } finally {
                // to enable garbage collection
                document.removeField(SolrFieldConstants.FULLTEXT_FIELD);
            }
        }
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) LazyFulltextFieldImpl(cz.mzk.recordmanager.server.index.enrich.LazyFulltextFieldImpl) SolrException(org.apache.solr.common.SolrException)

Example 43 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project RecordManager2 by moravianlibrary.

the class SolrServerFacadeImpl method fallbackIndex.

private void fallbackIndex(Collection<SolrInputDocument> documents, int commitWithinMs) throws SolrServerException {
    for (SolrInputDocument document : documents) {
        boolean carryOn = true;
        while (carryOn) {
            try {
                server.add(document, commitWithinMs);
                exceptionHandler.ok();
                carryOn = false;
            } catch (SolrException | SolrServerException | IOException ex) {
                Action action = exceptionHandler.handle(ex, documents);
                carryOn = action == Action.RETRY;
            }
        }
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) Action(cz.mzk.recordmanager.server.solr.SolrIndexingExceptionHandler.Action) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) SolrException(org.apache.solr.common.SolrException)

Example 44 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project RecordManager2 by moravianlibrary.

the class SolrServerFacadeImpl method query.

public QueryResponse query(SolrQuery query) throws SolrServerException {
    if (requestPath == null) {
        return server.query(query);
    } else {
        SolrRequest request = new QueryRequest(query);
        request.setPath(requestPath);
        NamedList<Object> req;
        try {
            req = server.request(request);
        } catch (IOException ioe) {
            throw new SolrServerException(ioe);
        }
        return new QueryResponse(req, server);
    }
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) SolrRequest(org.apache.solr.client.solrj.SolrRequest) SolrServerException(org.apache.solr.client.solrj.SolrServerException) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) IOException(java.io.IOException)

Example 45 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project RecordManager2 by moravianlibrary.

the class AbstractKrameriusTest method initSolrServerWithException.

protected void initSolrServerWithException() throws Exception {
    reset(solrServerFactory);
    expect(solrServerFactory.create(eq(SOLR_URL), eq(Mode.KRAMERIUS))).andReturn(mockedSolrServer).anyTimes();
    replay(solrServerFactory);
    reset(mockedSolrServer);
    Capture<SolrQuery> capturedQueryRequest = EasyMock.newCapture();
    SolrDocumentList documents = new SolrDocumentList();
    SolrDocument doc1 = new SolrDocument();
    doc1.addField("PID", "uuid:00931210-02b6-11e5-b939-0800200c9a66");
    SolrDocument doc2 = new SolrDocument();
    doc2.addField("PID", "uuid:0095bca0-614f-11e2-bcfd-0800200c9a66");
    documents.add(doc1);
    documents.add(doc2);
    NamedList<Object> solrResponse1 = new NamedList<Object>();
    solrResponse1.add("response", documents);
    // 1st response - SolrServerExceptions
    expect(mockedSolrServer.query(and(capture(capturedQueryRequest), anyObject(SolrQuery.class)))).andThrow(new SolrServerException("Bad status code: 500"));
    // 2nd response - SolrServerException
    expect(mockedSolrServer.query(and(capture(capturedQueryRequest), anyObject(SolrQuery.class)))).andThrow(new SolrServerException("Something bad happened to poor SOLR"));
    // 3rd response - OK
    expect(mockedSolrServer.query(and(capture(capturedQueryRequest), anyObject(SolrQuery.class)))).andReturn(new QueryResponse(solrResponse1, null));
    replay(mockedSolrServer);
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) NamedList(org.apache.solr.common.util.NamedList) SolrServerException(org.apache.solr.client.solrj.SolrServerException) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) EasyMock.anyObject(org.easymock.EasyMock.anyObject) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Aggregations

SolrServerException (org.apache.solr.client.solrj.SolrServerException)281 IOException (java.io.IOException)210 SolrQuery (org.apache.solr.client.solrj.SolrQuery)101 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)97 ArrayList (java.util.ArrayList)58 SolrException (org.apache.solr.common.SolrException)57 SolrDocument (org.apache.solr.common.SolrDocument)55 SolrInputDocument (org.apache.solr.common.SolrInputDocument)50 SolrDocumentList (org.apache.solr.common.SolrDocumentList)44 HashMap (java.util.HashMap)30 Map (java.util.Map)29 List (java.util.List)27 UpdateResponse (org.apache.solr.client.solrj.response.UpdateResponse)26 SolrClient (org.apache.solr.client.solrj.SolrClient)23 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)23 NamedList (org.apache.solr.common.util.NamedList)22 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)19 Date (java.util.Date)18 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)17 SolrParams (org.apache.solr.common.params.SolrParams)13