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.");
}
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;
}
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;
}
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);
}
}
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));
}
}
Aggregations