Example usage for org.apache.solr.common.util NamedList removeConfigArgs

List of usage examples for org.apache.solr.common.util NamedList removeConfigArgs

Introduction

In this page you can find the example usage for org.apache.solr.common.util NamedList removeConfigArgs.

Prototype

@SuppressWarnings("rawtypes")
public Collection<String> removeConfigArgs(final String name) throws SolrException 

Source Link

Document

Used for getting one or many arguments from NamedList objects that hold configuration parameters.

Usage

From source file:com.sindicetech.siren.solr.facet.SirenFacetProcessorFactory.java

License:Open Source License

/**
 * //from  w ww . ja  v  a2  s. c o m
 * Taken from {@link AddSchemaFieldsUpdateProcessorFactory}'s parseTypeMappings().
 * 
 * @param args
 * @return
 */
@SuppressWarnings("rawtypes")
private List<TypeMapping> parseTypeMappings(NamedList args) {
    List<TypeMapping> typeMappings = new ArrayList<TypeMapping>();
    List typeMappingsParams = args.getAll(TYPE_MAPPING_PARAM);
    for (Object typeMappingObj : typeMappingsParams) {
        if (null == typeMappingObj) {
            throw new SolrException(SERVER_ERROR, "'" + TYPE_MAPPING_PARAM + "' init param cannot be null");
        }
        if (!(typeMappingObj instanceof NamedList)) {
            throw new SolrException(SERVER_ERROR, "'" + TYPE_MAPPING_PARAM + "' init param must be a <lst>");
        }
        NamedList typeMappingNamedList = (NamedList) typeMappingObj;

        Object fieldTypeObj = typeMappingNamedList.remove(FIELD_TYPE_PARAM);
        if (null == fieldTypeObj) {
            throw new SolrException(SERVER_ERROR,
                    "Each '" + TYPE_MAPPING_PARAM + "' <lst/> must contain a '" + FIELD_TYPE_PARAM + "' <str>");
        }
        if (!(fieldTypeObj instanceof CharSequence)) {
            throw new SolrException(SERVER_ERROR, "'" + FIELD_TYPE_PARAM + "' init param must be a <str>");
        }
        if (null != typeMappingNamedList.get(FIELD_TYPE_PARAM)) {
            throw new SolrException(SERVER_ERROR, "Each '" + TYPE_MAPPING_PARAM
                    + "' <lst/> may contain only one '" + FIELD_TYPE_PARAM + "' <str>");
        }
        String fieldType = fieldTypeObj.toString();

        Object maxFieldSizeObj = typeMappingNamedList.remove(MAX_FIELD_SIZE_PARAM);
        if (maxFieldSizeObj != null) {
            if (!(maxFieldSizeObj instanceof Integer)) {
                throw new SolrException(SERVER_ERROR, "'" + FIELD_TYPE_PARAM + "' init param must be an <int>");
            }
        }

        Collection<String> valueClasses = typeMappingNamedList.removeConfigArgs(VALUE_CLASS_PARAM);
        if (valueClasses.isEmpty()) {
            throw new SolrException(SERVER_ERROR, "Each '" + TYPE_MAPPING_PARAM
                    + "' <lst/> must contain at least one '" + VALUE_CLASS_PARAM + "' <str>");
        }
        typeMappings.add(new TypeMapping(fieldType, (Integer) maxFieldSizeObj, valueClasses));

        if (0 != typeMappingNamedList.size()) {
            throw new SolrException(SERVER_ERROR, "Unexpected '" + TYPE_MAPPING_PARAM + "' init sub-param(s): '"
                    + typeMappingNamedList.toString() + "'");
        }
        args.remove(TYPE_MAPPING_PARAM);
    }

    checkMappingExists(typeMappings, FacetDatatype.BOOLEAN.xsdDatatype);
    checkMappingExists(typeMappings, FacetDatatype.DOUBLE.xsdDatatype);
    checkMappingExists(typeMappings, FacetDatatype.LONG.xsdDatatype);
    checkMappingExists(typeMappings, FacetDatatype.STRING.xsdDatatype);

    return typeMappings;
}