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);
}
}
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);
}
}
}
}
}
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);
}
}
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");
}
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");
}
Aggregations