Example usage for org.apache.solr.common.params ShardParams SHARDS_TOLERANT

List of usage examples for org.apache.solr.common.params ShardParams SHARDS_TOLERANT

Introduction

In this page you can find the example usage for org.apache.solr.common.params ShardParams SHARDS_TOLERANT.

Prototype

String SHARDS_TOLERANT

To view the source code for org.apache.solr.common.params ShardParams SHARDS_TOLERANT.

Click Source Link

Document

Should things fail if there is an error?

Usage

From source file:org.alfresco.solr.component.spellcheck.AlfrescoSpellCheckBackCompatComponent.java

License:Open Source License

public void finishStage(ResponseBuilder rb) {
    if (!rb.req.getParams().getBool(SpellCheckComponent.COMPONENT_NAME, false)
            || rb.stage != ResponseBuilder.STAGE_GET_FIELDS)
        return;// w  w w  .  j a  va  2 s.c o  m

    Map extras = new HashMap();
    for (ShardRequest sreq : rb.finished) {
        for (ShardResponse srsp : sreq.responses) {
            NamedList nl = null;

            try {
                nl = (NamedList) srsp.getSolrResponse().getResponse().get("spellcheck-extras");
            } catch (Exception e) {
                if (rb.req.getParams().getBool(ShardParams.SHARDS_TOLERANT, false)) {
                    continue; // looks like a shard did not return anything
                }
                throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
                        "Unable to read spelling info for shard: " + srsp.getShard(), e);
            }

            if (nl != null) {
                collectExtras(nl, extras);
            }
        }
    }

    if (extras.size() == 0) {
        return;
    }

    NamedList response = rb.rsp.getValues();
    NamedList spellcheck = (NamedList) response.get("spellcheck");

    if (spellcheck == null) {
        return;
    }

    NamedList collations = (NamedList) spellcheck.get("collations");
    NamedList suggestions = (NamedList) spellcheck.get("suggestions");

    if (collations != null) {
        //Fix up the collationQueryString in Solr 6
        for (int i = 0; i < collations.size(); i++) {
            if ("collation".equals(collations.getName(i))) {
                NamedList collation = (NamedList) collations.getVal(i);
                String collationQuery = (String) collation.get("collationQuery");
                String collationQueryString = (String) extras.get(collationQuery);
                collation.add("collationQueryString", collationQueryString);
            }
        }
        //Add the collations to the suggestions to support the Solr 4 format
        suggestions.addAll(collations);
    } else {
        //Fix up the collationQueryString Solr4
        for (int i = 0; i < suggestions.size(); i++) {
            if ("collation".equals(suggestions.getName(i))) {
                NamedList collation = (NamedList) suggestions.getVal(i);
                String collationQuery = (String) collation.get("collationQuery");
                String collationQueryString = (String) extras.get(collationQuery);
                collation.add("collationQueryString", collationQueryString);
            }
        }
    }
}