SOLR-642: make ShardResponse public

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@678620 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2008-07-22 02:34:00 +00:00
parent 4f03b00164
commit d8779e18ae
7 changed files with 95 additions and 50 deletions

View File

@ -113,7 +113,7 @@ public class DebugComponent extends SearchComponent
for (ShardRequest sreq : rb.finished) {
if ((sreq.purpose & ShardRequest.PURPOSE_GET_DEBUG) == 0) continue;
for (ShardResponse srsp : sreq.responses) {
NamedList sdebug = (NamedList)srsp.rsp.getResponse().get("debug");
NamedList sdebug = (NamedList)srsp.getSolrResponse().getResponse().get("debug");
info = (NamedList)merge(sdebug, info, excludeSet);
NamedList sexplain = (NamedList)sdebug.get("explain");

View File

@ -198,8 +198,8 @@ public class FacetComponent extends SearchComponent
FacetInfo fi = rb._facetInfo;
for (ShardResponse srsp: sreq.responses) {
int shardNum = rb.getShardNum(srsp.shard);
NamedList facet_counts = (NamedList)srsp.rsp.getResponse().get("facet_counts");
int shardNum = rb.getShardNum(srsp.getShard());
NamedList facet_counts = (NamedList)srsp.getSolrResponse().getResponse().get("facet_counts");
// handle facet queries
NamedList facet_queries = (NamedList)facet_counts.get("facet_queries");
@ -287,7 +287,7 @@ public class FacetComponent extends SearchComponent
for (ShardResponse srsp: sreq.responses) {
// int shardNum = rb.getShardNum(srsp.shard);
NamedList facet_counts = (NamedList)srsp.rsp.getResponse().get("facet_counts");
NamedList facet_counts = (NamedList)srsp.getSolrResponse().getResponse().get("facet_counts");
NamedList facet_queries = (NamedList)facet_counts.get("facet_queries");
// These are single term queries used to fill in missing counts

View File

@ -114,7 +114,7 @@ public class HighlightComponent extends SearchComponent
for (ShardRequest sreq : rb.finished) {
if ((sreq.purpose & ShardRequest.PURPOSE_GET_HIGHLIGHTS) == 0) continue;
for (ShardResponse srsp : sreq.responses) {
NamedList hl = (NamedList)srsp.rsp.getResponse().get("highlighting");
NamedList hl = (NamedList)srsp.getSolrResponse().getResponse().get("highlighting");
for (int i=0; i<hl.size(); i++) {
String id = hl.getName(i);
ShardDoc sdoc = rb.resultIds.get(id);

View File

@ -354,7 +354,7 @@ public class QueryComponent extends SearchComponent
long numFound = 0;
Float maxScore=null;
for (ShardResponse srsp : sreq.responses) {
SolrDocumentList docs = (SolrDocumentList)srsp.rsp.getResponse().get("response");
SolrDocumentList docs = (SolrDocumentList)srsp.getSolrResponse().getResponse().get("response");
// calculate global maxScore and numDocsFound
if (docs.getMaxScore() != null) {
@ -362,7 +362,7 @@ public class QueryComponent extends SearchComponent
}
numFound += docs.getNumFound();
NamedList sortFieldValues = (NamedList)(srsp.rsp.getResponse().get("sort_values"));
NamedList sortFieldValues = (NamedList)(srsp.getSolrResponse().getResponse().get("sort_values"));
// go through every doc in this response, construct a ShardDoc, and
// put it in the priority queue so it can be ordered.
@ -370,7 +370,7 @@ public class QueryComponent extends SearchComponent
SolrDocument doc = docs.get(i);
Object id = doc.getFieldValue(uniqueKeyField.getName());
String prevShard = uniqueDoc.put(id, srsp.shard);
String prevShard = uniqueDoc.put(id, srsp.getShard());
if (prevShard != null) {
// duplicate detected
numFound--;
@ -388,7 +388,7 @@ public class QueryComponent extends SearchComponent
ShardDoc shardDoc = new ShardDoc();
shardDoc.id = id;
shardDoc.shard = srsp.shard;
shardDoc.shard = srsp.getShard();
shardDoc.orderInShard = i;
Object scoreObj = doc.getFieldValue("score");
if (scoreObj != null) {
@ -502,7 +502,7 @@ public class QueryComponent extends SearchComponent
assert(sreq.responses.size() == 1);
ShardResponse srsp = sreq.responses.get(0);
SolrDocumentList docs = (SolrDocumentList)srsp.rsp.getResponse().get("response");
SolrDocumentList docs = (SolrDocumentList)srsp.getSolrResponse().getResponse().get("response");
String keyFieldName = rb.req.getSchema().getUniqueKeyField().getName();

View File

@ -235,20 +235,20 @@ public class SearchHandler extends RequestHandlerBase implements SolrCoreAware
// Was there an exception? If so, abort everything and
// rethrow
if (srsp.exception != null) {
if (srsp.getException() != null) {
comm.cancelAll();
if (srsp.exception instanceof SolrException) {
throw (SolrException)srsp.exception;
if (srsp.getException() instanceof SolrException) {
throw (SolrException)srsp.getException();
} else {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, srsp.exception);
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, srsp.getException());
}
}
rb.finished.add(srsp.req);
rb.finished.add(srsp.getShardRequest());
// let the components see the responses to the request
for(SearchComponent c : components) {
c.handleResponses(rb, srsp.req);
c.handleResponses(rb, srsp.getShardRequest());
}
}
}
@ -346,10 +346,10 @@ class HttpCommComponent {
public ShardResponse call() throws Exception {
ShardResponse srsp = new ShardResponse();
srsp.req = sreq;
srsp.shard = shard;
srsp.setShardRequest(sreq);
srsp.setShard(shard);
SimpleSolrResponse ssr = new SimpleSolrResponse();
srsp.rsp = ssr;
srsp.setSolrResponse(ssr);
long startTime = System.currentTimeMillis();
try {
@ -370,11 +370,11 @@ class HttpCommComponent {
ssr.nl = server.request(req);
} catch (Throwable th) {
srsp.exception = th;
srsp.setException(th);
if (th instanceof SolrException) {
srsp.rspCode = ((SolrException)th).code();
srsp.setResponseCode(((SolrException)th).code());
} else {
srsp.rspCode = -1;
srsp.setResponseCode(-1);
}
}
@ -394,8 +394,8 @@ class HttpCommComponent {
Future<ShardResponse> future = completionService.take();
pending.remove(future);
ShardResponse rsp = future.get();
rsp.req.responses.add(rsp);
if (rsp.req.responses.size() == rsp.req.actualShards.length) {
rsp.getShardRequest().responses.add(rsp);
if (rsp.getShardRequest().responses.size() == rsp.getShardRequest().actualShards.length) {
return rsp;
}
} catch (InterruptedException e) {
@ -419,13 +419,13 @@ class HttpCommComponent {
Future<ShardResponse> future = completionService.take();
pending.remove(future);
ShardResponse rsp = future.get();
if (rsp.exception != null) return rsp; // if exception, return immediately
if (rsp.getException() != null) return rsp; // if exception, return immediately
// add response to the response list... we do this after the take() and
// not after the completion of "call" so we know when the last response
// for a request was received. Otherwise we might return the same
// request more than once.
rsp.req.responses.add(rsp);
if (rsp.req.responses.size() == rsp.req.actualShards.length) {
rsp.getShardRequest().responses.add(rsp);
if (rsp.getShardRequest().responses.size() == rsp.getShardRequest().actualShards.length) {
return rsp;
}
} catch (InterruptedException e) {

View File

@ -16,14 +16,11 @@
*/
package org.apache.solr.handler.component;
import org.apache.solr.client.solrj.SolrResponse;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.util.NamedList;
import java.util.ArrayList;
import java.util.List;
import org.apache.solr.common.params.ModifiableSolrParams;
// todo... when finalized make accessors
public class ShardRequest {
@ -66,21 +63,3 @@ public class ShardRequest {
+ "}";
}
}
class ShardResponse {
public ShardRequest req;
public String shard;
public String shardAddress; // the specific shard that this response was received from
public int rspCode;
public Throwable exception;
public SolrResponse rsp;
public String toString() {
return "ShardResponse:{shard="+shard+",shardAddress="+shardAddress
+"\n\trequest=" + req
+"\n\tresponse=" + rsp
+ (exception==null ? "" : "\n\texception="+ SolrException.toStr(exception))
+"\n}";
}
}

View File

@ -0,0 +1,66 @@
package org.apache.solr.handler.component;
import org.apache.solr.client.solrj.SolrResponse;
import org.apache.solr.common.SolrException;
public final class ShardResponse {
private ShardRequest req;
private String shard;
private String shardAddress; // the specific shard that this response was received from
private int rspCode;
private Throwable exception;
private SolrResponse rsp;
public String toString() {
return "ShardResponse:{shard="+shard+",shardAddress="+shardAddress
+"\n\trequest=" + req
+"\n\tresponse=" + rsp
+ (exception==null ? "" : "\n\texception="+ SolrException.toStr(exception))
+"\n}";
}
public Throwable getException()
{
return exception;
}
public ShardRequest getShardRequest()
{
return req;
}
public SolrResponse getSolrResponse()
{
return rsp;
}
public String getShard()
{
return shard;
}
void setShardRequest(ShardRequest rsp)
{
this.req = rsp;
}
void setSolrResponse(SolrResponse rsp)
{
this.rsp = rsp;
}
void setShard(String shard)
{
this.shard = shard;
}
void setException(Throwable exception)
{
this.exception = exception;
}
void setResponseCode(int rspCode)
{
this.rspCode = rspCode;
}
}