Search in sources :

Example 1 with ShardResponse

use of org.apache.solr.handler.component.ShardResponse in project lucene-solr by apache.

the class StoredFieldsShardResponseProcessor method process.

/**
   * {@inheritDoc}
   */
@Override
public void process(ResponseBuilder rb, ShardRequest shardRequest) {
    boolean returnScores = (rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0;
    ShardResponse srsp = shardRequest.responses.get(0);
    SolrDocumentList docs = (SolrDocumentList) srsp.getSolrResponse().getResponse().get("response");
    String uniqueIdFieldName = rb.req.getSchema().getUniqueKeyField().getName();
    for (SolrDocument doc : docs) {
        Object id = doc.getFieldValue(uniqueIdFieldName).toString();
        ShardDoc shardDoc = rb.resultIds.get(id);
        FieldDoc fieldDoc = (FieldDoc) shardDoc;
        if (shardDoc != null) {
            if (returnScores && !Float.isNaN(fieldDoc.score)) {
                doc.setField("score", fieldDoc.score);
            }
            rb.retrievedDocuments.put(id, doc);
        }
    }
}
Also used : ShardResponse(org.apache.solr.handler.component.ShardResponse) SolrDocument(org.apache.solr.common.SolrDocument) FieldDoc(org.apache.lucene.search.FieldDoc) SolrDocumentList(org.apache.solr.common.SolrDocumentList) ShardDoc(org.apache.solr.handler.component.ShardDoc)

Example 2 with ShardResponse

use of org.apache.solr.handler.component.ShardResponse in project lucene-solr by apache.

the class ExactStatsCache method mergeToGlobalStats.

@Override
public void mergeToGlobalStats(SolrQueryRequest req, List<ShardResponse> responses) {
    Set<Object> allTerms = new HashSet<>();
    for (ShardResponse r : responses) {
        LOG.debug("Merging to global stats, shard={}, response={}", r.getShard(), r.getSolrResponse().getResponse());
        String shard = r.getShard();
        SolrResponse res = r.getSolrResponse();
        NamedList<Object> nl = res.getResponse();
        // TODO: nl == null if not all shards respond (no server hosting shard)
        String termStatsString = (String) nl.get(TERM_STATS_KEY);
        if (termStatsString != null) {
            addToPerShardTermStats(req, shard, termStatsString);
        }
        List<Object> terms = nl.getAll(TERMS_KEY);
        allTerms.addAll(terms);
        String colStatsString = (String) nl.get(COL_STATS_KEY);
        Map<String, CollectionStats> colStats = StatsUtil.colStatsMapFromString(colStatsString);
        if (colStats != null) {
            addToPerShardColStats(req, shard, colStats);
        }
    }
    if (allTerms.size() > 0) {
        req.getContext().put(TERMS_KEY, Lists.newArrayList(allTerms));
    }
    if (LOG.isDebugEnabled())
        printStats(req);
}
Also used : ShardResponse(org.apache.solr.handler.component.ShardResponse) SolrResponse(org.apache.solr.client.solrj.SolrResponse) HashSet(java.util.HashSet)

Example 3 with ShardResponse

use of org.apache.solr.handler.component.ShardResponse in project lucene-solr by apache.

the class FacetQueryMerger method handleResponses.

@Override
public void handleResponses(ResponseBuilder rb, ShardRequest sreq) {
    FacetComponentState facetState = getFacetComponentState(rb);
    if (facetState == null)
        return;
    for (ShardResponse shardRsp : sreq.responses) {
        SolrResponse rsp = shardRsp.getSolrResponse();
        NamedList<Object> top = rsp.getResponse();
        // shards.tolerant=true will cause this to happen on exceptions/errors
        if (top == null)
            continue;
        Object facet = top.get("facets");
        if (facet == null)
            continue;
        if (facetState.merger == null) {
            facetState.merger = facetState.facetRequest.createFacetMerger(facet);
            facetState.mcontext = new FacetMerger.Context(sreq.responses.size());
        }
        if ((sreq.purpose & PURPOSE_REFINE_JSON_FACETS) != 0) {
            System.err.println("REFINE FACET RESULT FROM SHARD = " + facet);
            // call merge again with a diff flag set on the context???
            //        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "WORK IN PROGRESS, MERGING FACET REFINEMENT NOT SUPPORTED YET!");
            facetState.mcontext.root = facet;
            // TODO: roll newShard into setShard?
            facetState.mcontext.setShard(shardRsp.getShard());
            facetState.merger.merge(facet, facetState.mcontext);
            return;
        }
        facetState.mcontext.root = facet;
        facetState.mcontext.newShard(shardRsp.getShard());
        facetState.merger.merge(facet, facetState.mcontext);
    }
}
Also used : ShardResponse(org.apache.solr.handler.component.ShardResponse) SolrResponse(org.apache.solr.client.solrj.SolrResponse)

Example 4 with ShardResponse

use of org.apache.solr.handler.component.ShardResponse in project lucene-solr by apache.

the class PeerSync method alreadyInSync.

/**
   * Check if we are already in sync. Simple fingerprint comparison should do
   */
private boolean alreadyInSync() {
    for (String replica : replicas) {
        requestFingerprint(replica);
    }
    for (; ; ) {
        ShardResponse srsp = shardHandler.takeCompletedOrError();
        if (srsp == null)
            break;
        Object replicaFingerprint = srsp.getSolrResponse().getResponse().get("fingerprint");
        if (replicaFingerprint == null) {
            log.warn("Replica did not return a fingerprint - possibly an older Solr version");
            continue;
        }
        try {
            IndexFingerprint otherFingerprint = IndexFingerprint.fromObject(replicaFingerprint);
            IndexFingerprint ourFingerprint = IndexFingerprint.getFingerprint(core, Long.MAX_VALUE);
            if (IndexFingerprint.compare(otherFingerprint, ourFingerprint) == 0) {
                log.info("We are already in sync. No need to do a PeerSync ");
                return true;
            }
        } catch (IOException e) {
            log.warn("Could not cofirm if we are already in sync. Continue with PeerSync");
        }
    }
    return false;
}
Also used : ShardResponse(org.apache.solr.handler.component.ShardResponse) IOException(java.io.IOException)

Example 5 with ShardResponse

use of org.apache.solr.handler.component.ShardResponse in project lucene-solr by apache.

the class OverseerCollectionMessageHandler method processResponses.

void processResponses(NamedList results, ShardHandler shardHandler, boolean abortOnError, String msgOnError, String asyncId, Map<String, String> requestMap, Set<String> okayExceptions) {
    //Processes all shard responses
    ShardResponse srsp;
    do {
        srsp = shardHandler.takeCompletedOrError();
        if (srsp != null) {
            processResponse(results, srsp, okayExceptions);
            Throwable exception = srsp.getException();
            if (abortOnError && exception != null) {
                // drain pending requests
                while (srsp != null) {
                    srsp = shardHandler.takeCompletedOrError();
                }
                throw new SolrException(ErrorCode.SERVER_ERROR, msgOnError, exception);
            }
        }
    } while (srsp != null);
    //If request is async wait for the core admin to complete before returning
    if (asyncId != null) {
        waitForAsyncCallsToComplete(requestMap, results);
        requestMap.clear();
    }
}
Also used : ShardResponse(org.apache.solr.handler.component.ShardResponse) RemoteSolrException(org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException) SolrException(org.apache.solr.common.SolrException)

Aggregations

ShardResponse (org.apache.solr.handler.component.ShardResponse)15 NamedList (org.apache.solr.common.util.NamedList)6 ArrayList (java.util.ArrayList)5 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)5 SolrException (org.apache.solr.common.SolrException)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 SolrServerException (org.apache.solr.client.solrj.SolrServerException)3 ShardHandler (org.apache.solr.handler.component.ShardHandler)3 ShardRequest (org.apache.solr.handler.component.ShardRequest)3 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 HashSet (java.util.HashSet)2 Sort (org.apache.lucene.search.Sort)2 BytesRef (org.apache.lucene.util.BytesRef)2 SolrResponse (org.apache.solr.client.solrj.SolrResponse)2 RemoteSolrException (org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException)2 SolrParams (org.apache.solr.common.params.SolrParams)2