Search in sources :

Example 6 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project ORCID-Source by ORCID.

the class FundingSubtypeSolrDaoImpl method getFundingTypes.

@Override
public List<OrgDefinedFundingTypeSolrDocument> getFundingTypes(String searchTerm, int firstResult, int maxResult) {
    SolrQuery query = new SolrQuery();
    query.setQuery("{!edismax qf='org-defined-funding-type^50.0 text^1.0' pf='org-defined-funding-type^50.0' mm=1 sort='score desc'}" + searchTerm + "*").setFields("*");
    try {
        QueryResponse queryResponse = solrServerReadOnly.query(query);
        return queryResponse.getBeans(OrgDefinedFundingTypeSolrDocument.class);
    } catch (SolrServerException se) {
        String errorMessage = MessageFormat.format("Error when attempting to search for orgs, with search term {0}", new Object[] { searchTerm });
        throw new NonTransientDataAccessResourceException(errorMessage, se);
    }
}
Also used : NonTransientDataAccessResourceException(org.springframework.dao.NonTransientDataAccessResourceException) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 7 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project lucene-solr by apache.

the class QueryComponent method returnFields.

protected void returnFields(ResponseBuilder rb, ShardRequest sreq) {
    if ((sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS) != 0) {
        boolean returnScores = (rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0;
        String keyFieldName = rb.req.getSchema().getUniqueKeyField().getName();
        boolean removeKeyField = !rb.rsp.getReturnFields().wantsField(keyFieldName);
        if (rb.rsp.getReturnFields().getFieldRenames().get(keyFieldName) != null) {
            // if id was renamed we need to use the new name
            keyFieldName = rb.rsp.getReturnFields().getFieldRenames().get(keyFieldName);
        }
        for (ShardResponse srsp : sreq.responses) {
            if (srsp.getException() != null) {
                // Don't try to get the documents if there was an exception in the shard
                if (rb.req.getParams().getBool(ShardParams.SHARDS_INFO, false)) {
                    @SuppressWarnings("unchecked") NamedList<Object> shardInfo = (NamedList<Object>) rb.rsp.getValues().get(ShardParams.SHARDS_INFO);
                    @SuppressWarnings("unchecked") SimpleOrderedMap<Object> nl = (SimpleOrderedMap<Object>) shardInfo.get(srsp.getShard());
                    if (nl.get("error") == null) {
                        // Add the error to the shards info section if it wasn't added before
                        Throwable t = srsp.getException();
                        if (t instanceof SolrServerException) {
                            t = ((SolrServerException) t).getCause();
                        }
                        nl.add("error", t.toString());
                        StringWriter trace = new StringWriter();
                        t.printStackTrace(new PrintWriter(trace));
                        nl.add("trace", trace.toString());
                    }
                }
                continue;
            }
            SolrDocumentList docs = (SolrDocumentList) srsp.getSolrResponse().getResponse().get("response");
            for (SolrDocument doc : docs) {
                Object id = doc.getFieldValue(keyFieldName);
                ShardDoc sdoc = rb.resultIds.get(id.toString());
                if (sdoc != null) {
                    if (returnScores) {
                        doc.setField("score", sdoc.score);
                    } else {
                        // Score might have been added (in createMainQuery) to shard-requests (and therefore in shard-response-docs)
                        // Remove score if the outer request did not ask for it returned
                        doc.remove("score");
                    }
                    if (removeKeyField) {
                        doc.removeFields(keyFieldName);
                    }
                    rb.getResponseDocs().set(sdoc.positionInResponse, doc);
                }
            }
        }
    }
}
Also used : NamedList(org.apache.solr.common.util.NamedList) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) SolrDocument(org.apache.solr.common.SolrDocument) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Example 8 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project lucene-solr by apache.

the class IndexFetcher method getLatestVersion.

/**
   * Gets the latest commit version and generation from the master
   */
@SuppressWarnings("unchecked")
NamedList getLatestVersion() throws IOException {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set(COMMAND, CMD_INDEX_VERSION);
    params.set(CommonParams.WT, JAVABIN);
    params.set(CommonParams.QT, ReplicationHandler.PATH);
    QueryRequest req = new QueryRequest(params);
    // TODO modify to use shardhandler
    try (HttpSolrClient client = new Builder(masterUrl).withHttpClient(myHttpClient).build()) {
        client.setSoTimeout(soTimeout);
        client.setConnectionTimeout(connTimeout);
        return client.request(req);
    } catch (SolrServerException e) {
        throw new SolrException(ErrorCode.SERVER_ERROR, e.getMessage(), e);
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) Builder(org.apache.solr.client.solrj.impl.HttpSolrClient.Builder) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrException(org.apache.solr.common.SolrException)

Example 9 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project lucene-solr by apache.

the class TestTolerantSearch method testGetTopIdsPhaseError.

@SuppressWarnings("unchecked")
public void testGetTopIdsPhaseError() throws SolrServerException, IOException {
    BadResponseWriter.failOnGetTopIds = true;
    BadResponseWriter.failOnGetFields = false;
    SolrQuery query = new SolrQuery();
    query.setQuery("subject:batman OR subject:superman");
    query.addField("id");
    query.addField("subject");
    query.set("distrib", "true");
    query.set("shards", shard1 + "," + shard2);
    query.set(ShardParams.SHARDS_INFO, "true");
    query.set("debug", "true");
    query.set("stats", "true");
    query.set("stats.field", "id");
    query.set("mlt", "true");
    query.set("mlt.fl", "title");
    query.set("mlt.count", "1");
    query.set("mlt.mintf", "0");
    query.set("mlt.mindf", "0");
    query.setHighlight(true);
    query.addFacetField("id");
    query.setFacet(true);
    ignoreException("Dummy exception in BadResponseWriter");
    try {
        collection1.query(query);
        fail("Should get an exception");
    } catch (Exception e) {
    //expected
    }
    query.set(ShardParams.SHARDS_TOLERANT, "true");
    QueryResponse response = collection1.query(query);
    assertTrue(response.getResponseHeader().getBooleanArg(SolrQueryResponse.RESPONSE_HEADER_PARTIAL_RESULTS_KEY));
    NamedList<Object> shardsInfo = ((NamedList<Object>) response.getResponse().get(ShardParams.SHARDS_INFO));
    boolean foundError = false;
    for (int i = 0; i < shardsInfo.size(); i++) {
        if (shardsInfo.getName(i).contains("collection2")) {
            assertNotNull(((NamedList<Object>) shardsInfo.getVal(i)).get("error"));
            foundError = true;
            break;
        }
    }
    assertTrue(foundError);
    assertEquals(1, response.getResults().get(0).getFieldValue("id"));
    assertEquals("batman", response.getResults().get(0).getFirstValue("subject"));
    unIgnoreException("Dummy exception in BadResponseWriter");
}
Also used : QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrQuery(org.apache.solr.client.solrj.SolrQuery) IOException(java.io.IOException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException)

Example 10 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project lucene-solr by apache.

the class TestTolerantSearch method testGetFieldsPhaseError.

@SuppressWarnings("unchecked")
public void testGetFieldsPhaseError() throws SolrServerException, IOException {
    BadResponseWriter.failOnGetFields = true;
    BadResponseWriter.failOnGetTopIds = false;
    SolrQuery query = new SolrQuery();
    query.setQuery("subject:batman OR subject:superman");
    query.addField("id");
    query.addField("subject");
    query.set("distrib", "true");
    query.set("shards", shard1 + "," + shard2);
    query.set(ShardParams.SHARDS_INFO, "true");
    query.set("debug", "true");
    query.set("stats", "true");
    query.set("stats.field", "id");
    query.set("mlt", "true");
    query.set("mlt.fl", "title");
    query.set("mlt.count", "1");
    query.set("mlt.mintf", "0");
    query.set("mlt.mindf", "0");
    query.setHighlight(true);
    query.addFacetField("id");
    query.setFacet(true);
    ignoreException("Dummy exception in BadResponseWriter");
    try {
        collection1.query(query);
        fail("Should get an exception");
    } catch (Exception e) {
    //expected
    }
    query.set(ShardParams.SHARDS_TOLERANT, "true");
    QueryResponse response = collection1.query(query);
    assertTrue(response.getResponseHeader().getBooleanArg(SolrQueryResponse.RESPONSE_HEADER_PARTIAL_RESULTS_KEY));
    NamedList<Object> shardsInfo = ((NamedList<Object>) response.getResponse().get(ShardParams.SHARDS_INFO));
    boolean foundError = false;
    for (int i = 0; i < shardsInfo.size(); i++) {
        if (shardsInfo.getName(i).contains("collection2")) {
            assertNotNull(((NamedList<Object>) shardsInfo.getVal(i)).get("error"));
            foundError = true;
            break;
        }
    }
    assertTrue(foundError);
    assertEquals(1, response.getResults().get(0).getFieldValue("id"));
    assertEquals("batman", response.getResults().get(0).getFirstValue("subject"));
    unIgnoreException("Dummy exception in BadResponseWriter");
}
Also used : QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrQuery(org.apache.solr.client.solrj.SolrQuery) IOException(java.io.IOException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException)

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