}
}
}
//we support only a single dataType ...
// ... therefore remove additional data types from the ValueConstraint
IndexDataType indexDataType = null;
if(!indexDataTypes.isEmpty()) {
indexDataType = indexDataTypes.get(0);
if(indexDataTypes.size() > 1){
log.warn("Only a single DataType is supported for ValueConstraints!");
while(acceptedDataTypes.size()>1){
String ignored = acceptedDataTypes.remove(acceptedDataTypes.size()-1);
log.warn(" > ignore parsed dataType {}",ignored);
}
}
} //else empty we will initialise based on the first parsed value!
ConstraintValue constraintValue = new ConstraintValue(valueConstraint.getMode());
addBoost(constraintValue, valueConstraint); //init the boost
for(Object value : valueConstraint.getValues()){
IndexValue indexValue;
if(indexDataType == null){ // if no supported types are present
// get the dataType based on the type of the value
try {
indexValue = indexValueFactory.createIndexValue(value);
} catch (NoConverterException e) {
// if not found use the toString() and string as type
log.warn("Unable to create IndexValue for value {} (type: {}). Create IndexValue manually by using the first parsed IndexDataType {}",
new Object[]{
value, value.getClass(),
IndexDataTypeEnum.STR.getIndexType()
});
indexValue = new IndexValue(value.toString(),
IndexDataTypeEnum.STR.getIndexType());
}
//initialise the IndexDataType for this query based on the first parsed value
indexDataType = indexValue.getType();
} else {
indexValue = new IndexValue(value.toString(), indexDataType);
}
constraintValue.getValues().add(indexValue); //add the constraint
}
//indexConstraint.setFieldConstraint(IndexConstraintTypeEnum.DATATYPE, indexDataType);
IndexField indexField;
if(IndexDataTypeEnum.TXT.getIndexType().equals(indexDataType)){
//NOTE: in case of TEXT we need also to add the language to create a valid
//query!
// * We take the language of the first parsed element
indexField = new IndexField(indexConstraint.getPath(), indexDataType,
constraintValue.getValues().iterator().next().getLanguage());
} else {
indexField = new IndexField(indexConstraint.getPath(), indexDataType);
}
//set FIELD, DATATYPE and LANGUAGE constraint by using the indexField
indexConstraint.setIndexFieldConstraints(indexField);
//set the VALUE
//TODO: We need to somehow pass the MODE so that the encoder knows how
// to encode the values
indexConstraint.setFieldConstraint(IndexConstraintTypeEnum.EQ, constraintValue);
//update this constraint!
if(valueConstraint instanceof ReferenceConstraint){
indexConstraint.setFieldQueryConstraint(valueConstraint);
} else {
indexConstraint.setFieldQueryConstraint(
new ValueConstraint(valueConstraint.getValues(), Arrays.asList(indexDataType.getId())));
}
}
}