Search in sources :

Example 46 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class StatsCollectorSupplierFactory method buildFieldSource.

/**
   *  Builds a value source for a given field, making sure that the field fits a given source type.
   * @param schema the schema
   * @param expressionString The name of the field to build a Field Source from.
   * @param sourceType FIELD_TYPE for any type of field, NUMBER_TYPE for numeric fields, 
   * DATE_TYPE for date fields and STRING_TYPE for string fields.
   * @return a value source
   */
private static ValueSource buildFieldSource(IndexSchema schema, String expressionString, int sourceType) {
    SchemaField sf;
    try {
        sf = schema.getField(expressionString);
    } catch (SolrException e) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "The field " + expressionString + " does not exist.", e);
    }
    FieldType type = sf.getType();
    if (type instanceof TrieIntField) {
        if (sourceType != NUMBER_TYPE && sourceType != FIELD_TYPE) {
            return null;
        }
        return new IntFieldSource(expressionString) {

            public String description() {
                return field;
            }
        };
    } else if (type instanceof TrieLongField) {
        if (sourceType != NUMBER_TYPE && sourceType != FIELD_TYPE) {
            return null;
        }
        return new LongFieldSource(expressionString) {

            public String description() {
                return field;
            }
        };
    } else if (type instanceof TrieFloatField) {
        if (sourceType != NUMBER_TYPE && sourceType != FIELD_TYPE) {
            return null;
        }
        return new FloatFieldSource(expressionString) {

            public String description() {
                return field;
            }
        };
    } else if (type instanceof TrieDoubleField) {
        if (sourceType != NUMBER_TYPE && sourceType != FIELD_TYPE) {
            return null;
        }
        return new DoubleFieldSource(expressionString) {

            public String description() {
                return field;
            }
        };
    } else if (type instanceof TrieDateField) {
        if (sourceType != DATE_TYPE && sourceType != FIELD_TYPE) {
            return null;
        }
        return new DateFieldSource(expressionString) {

            public String description() {
                return field;
            }
        };
    } else if (type instanceof StrField) {
        if (sourceType != STRING_TYPE && sourceType != FIELD_TYPE) {
            return null;
        }
        return new BytesRefFieldSource(expressionString) {

            public String description() {
                return field;
            }
        };
    }
    throw new SolrException(ErrorCode.BAD_REQUEST, type.toString() + " is not a supported field type in Solr Analytics.");
}
Also used : TrieDoubleField(org.apache.solr.schema.TrieDoubleField) StrField(org.apache.solr.schema.StrField) LongFieldSource(org.apache.lucene.queries.function.valuesource.LongFieldSource) TrieIntField(org.apache.solr.schema.TrieIntField) TrieDateField(org.apache.solr.schema.TrieDateField) BytesRefFieldSource(org.apache.lucene.queries.function.valuesource.BytesRefFieldSource) FieldType(org.apache.solr.schema.FieldType) SchemaField(org.apache.solr.schema.SchemaField) DoubleFieldSource(org.apache.lucene.queries.function.valuesource.DoubleFieldSource) IntFieldSource(org.apache.lucene.queries.function.valuesource.IntFieldSource) TrieLongField(org.apache.solr.schema.TrieLongField) FloatFieldSource(org.apache.lucene.queries.function.valuesource.FloatFieldSource) DateFieldSource(org.apache.solr.analytics.util.valuesource.DateFieldSource) SolrException(org.apache.solr.common.SolrException) TrieFloatField(org.apache.solr.schema.TrieFloatField)

Example 47 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class RangeEndpointCalculator method create.

public static RangeEndpointCalculator<? extends Comparable<?>> create(RangeFacetRequest request) {
    final SchemaField sf = request.getField();
    final FieldType ft = sf.getType();
    final RangeEndpointCalculator<?> calc;
    if (ft instanceof TrieField) {
        switch(ft.getNumberType()) {
            case FLOAT:
                calc = new FloatRangeEndpointCalculator(request);
                break;
            case DOUBLE:
                calc = new DoubleRangeEndpointCalculator(request);
                break;
            case INTEGER:
                calc = new IntegerRangeEndpointCalculator(request);
                break;
            case LONG:
                calc = new LongRangeEndpointCalculator(request);
                break;
            case DATE:
                calc = new DateRangeEndpointCalculator(request, null);
                break;
            default:
                throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unable to range facet on tried field of unexpected type:" + sf.getName());
        }
    } else {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unable to range facet on field:" + sf);
    }
    return calc;
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) TrieField(org.apache.solr.schema.TrieField) SolrException(org.apache.solr.common.SolrException) FieldType(org.apache.solr.schema.FieldType)

Example 48 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class LanguageIdentifierUpdateProcessor method process.

/**
   * This is the main, testable process method called from processAdd()
   * @param doc the SolrInputDocument to work on
   * @return the modified SolrInputDocument
   */
protected SolrInputDocument process(SolrInputDocument doc) {
    String docLang = null;
    HashSet<String> docLangs = new HashSet<>();
    String fallbackLang = getFallbackLang(doc, fallbackFields, fallbackValue);
    if (langField == null || !doc.containsKey(langField) || (doc.containsKey(langField) && overwrite)) {
        List<DetectedLanguage> languagelist = detectLanguage(doc);
        docLang = resolveLanguage(languagelist, fallbackLang);
        docLangs.add(docLang);
        log.debug("Detected main document language from fields " + Arrays.toString(inputFields) + ": " + docLang);
        if (doc.containsKey(langField) && overwrite) {
            log.debug("Overwritten old value " + doc.getFieldValue(langField));
        }
        if (langField != null && langField.length() != 0) {
            doc.setField(langField, docLang);
        }
    } else {
        // langField is set, we sanity check it against whitelist and fallback
        docLang = resolveLanguage((String) doc.getFieldValue(langField), fallbackLang);
        docLangs.add(docLang);
        log.debug("Field " + langField + " already contained value " + docLang + ", not overwriting.");
    }
    if (enableMapping) {
        for (String fieldName : allMapFieldsSet) {
            if (doc.containsKey(fieldName)) {
                String fieldLang;
                if (mapIndividual && mapIndividualFieldsSet.contains(fieldName)) {
                    List<DetectedLanguage> languagelist = detectLanguage(doc);
                    fieldLang = resolveLanguage(languagelist, docLang);
                    docLangs.add(fieldLang);
                    log.debug("Mapping field " + fieldName + " using individually detected language " + fieldLang);
                } else {
                    fieldLang = docLang;
                    log.debug("Mapping field " + fieldName + " using document global language " + fieldLang);
                }
                String mappedOutputField = getMappedField(fieldName, fieldLang);
                if (mappedOutputField != null) {
                    log.debug("Mapping field {} to {}", doc.getFieldValue(docIdField), fieldLang);
                    SolrInputField inField = doc.getField(fieldName);
                    doc.setField(mappedOutputField, inField.getValue());
                    if (!mapKeepOrig) {
                        log.debug("Removing old field {}", fieldName);
                        doc.removeField(fieldName);
                    }
                } else {
                    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Invalid output field mapping for " + fieldName + " field and language: " + fieldLang);
                }
            }
        }
    }
    // Set the languages field to an array of all detected languages
    if (langsField != null && langsField.length() != 0) {
        doc.setField(langsField, docLangs.toArray());
    }
    return doc;
}
Also used : SolrInputField(org.apache.solr.common.SolrInputField) SolrException(org.apache.solr.common.SolrException) HashSet(java.util.HashSet)

Example 49 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class ManagedModelStore method addModel.

public synchronized void addModel(LTRScoringModel ltrScoringModel) throws ModelException {
    try {
        log.info("adding model {}", ltrScoringModel.getName());
        store.addModel(ltrScoringModel);
    } catch (final ModelException e) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
    }
}
Also used : ModelException(org.apache.solr.ltr.model.ModelException) SolrException(org.apache.solr.common.SolrException)

Example 50 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class ManagedFeatureStore method doGet.

/**
   * Called to retrieve a named part (the given childId) of the resource at the
   * given endpoint. Note: since we have a unique child feature store we ignore
   * the childId.
   */
@Override
public void doGet(BaseSolrResource endpoint, String childId) {
    final SolrQueryResponse response = endpoint.getSolrResponse();
    // If no feature store specified, show all the feature stores available
    if (childId == null) {
        response.add(FEATURE_STORE_JSON_FIELD, stores.keySet());
    } else {
        final FeatureStore store = getFeatureStore(childId);
        if (store == null) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "missing feature store [" + childId + "]");
        }
        response.add(FEATURES_JSON_FIELD, featuresAsManagedResources(store));
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) FeatureStore(org.apache.solr.ltr.store.FeatureStore) SolrException(org.apache.solr.common.SolrException)

Aggregations

SolrException (org.apache.solr.common.SolrException)617 IOException (java.io.IOException)172 ArrayList (java.util.ArrayList)100 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)80 NamedList (org.apache.solr.common.util.NamedList)79 HashMap (java.util.HashMap)75 Map (java.util.Map)70 SolrParams (org.apache.solr.common.params.SolrParams)64 KeeperException (org.apache.zookeeper.KeeperException)60 Test (org.junit.Test)55 Replica (org.apache.solr.common.cloud.Replica)48 Slice (org.apache.solr.common.cloud.Slice)45 DocCollection (org.apache.solr.common.cloud.DocCollection)41 SolrInputDocument (org.apache.solr.common.SolrInputDocument)39 SchemaField (org.apache.solr.schema.SchemaField)39 List (java.util.List)38 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)38 SolrServerException (org.apache.solr.client.solrj.SolrServerException)37 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)34 SolrCore (org.apache.solr.core.SolrCore)33