use of io.vertigo.dynamox.search.dsl.model.DslMultiExpression in project vertigo by KleeGroup.
the class DslMultiExpressionRule method handle.
/**
* {@inheritDoc}
*/
@Override
protected DslMultiExpression handle(final PegChoice parsing) {
final String preMultiExpression;
final String postMultiExpression;
// ---
final List<PegChoice> many;
switch(parsing.getChoiceIndex()) {
case 0:
final List<?> blockExpression = (List<?>) parsing.getValue();
preMultiExpression = ((Optional<String>) blockExpression.get(0)).orElse("") + blockExpression.get(1);
many = (List<PegChoice>) blockExpression.get(3);
postMultiExpression = (String) blockExpression.get(5);
break;
case 1:
preMultiExpression = "";
many = (List<PegChoice>) parsing.getValue();
postMultiExpression = "";
break;
default:
throw new IllegalArgumentException("case " + parsing.getChoiceIndex() + " not implemented");
}
final List<DslExpression> expressionDefinitions = new ArrayList<>();
final List<DslMultiExpression> multiExpressionDefinitions = new ArrayList<>();
// On récupère le produit de la règle many
for (final PegChoice item : many) {
switch(item.getChoiceIndex()) {
case 0:
expressionDefinitions.add((DslExpression) item.getValue());
break;
case 1:
multiExpressionDefinitions.add((DslMultiExpression) item.getValue());
break;
default:
throw new IllegalArgumentException("case " + item.getChoiceIndex() + " not implemented");
}
}
final boolean block = parsing.getChoiceIndex() == 0;
// ---
return new DslMultiExpression(preMultiExpression, block, expressionDefinitions, multiExpressionDefinitions, postMultiExpression);
}
use of io.vertigo.dynamox.search.dsl.model.DslMultiExpression in project vertigo by KleeGroup.
the class DslListFilterBuilder method appendUserStringCriteria.
private boolean appendUserStringCriteria(final StringBuilder query, final DslTermQuery dslTermDefinition, final DslExpression expressionDefinition, final String userString, final StringBuilder outExpressionQuery) {
final List<DslUserCriteria> userCriteriaList = DslParserUtil.parseUserCriteria(userString);
// On compte les fields sur le field de la definition. Si >1 on mettra des ( )
int criteriaOnDefinitionField = 0;
for (final DslUserCriteria userCriteria : userCriteriaList) {
final String criteriaValue = userCriteria.getCriteriaWord();
if (!userCriteria.getOverridedFieldName().isEmpty()) {
// si le field est surchargé on flush l'expression précédente
flushExpressionToQuery(outExpressionQuery, expressionDefinition, query);
criteriaOnDefinitionField = 0;
// et on ajout la requete sur l'autre champs
outExpressionQuery.append(userCriteria.getPreMissingPart()).append(userCriteria.getOverridedFieldName()).append(userCriteria.getOverridedPreModifier()).append(criteriaValue).append(userCriteria.getOverridedPostModifier()).append(expressionDefinition.getPostBody()).append(userCriteria.getPostMissingPart());
} else if (expressionDefinition.getMultiField().isPresent()) {
criteriaOnDefinitionField++;
final DslMultiField dslMultiField = expressionDefinition.getMultiField().get();
query.append(userCriteria.getPreMissingPart());
final List<DslExpression> monoFieldExpressionDefinitions = flattenMultiToMonoFieldExpressionDefinition(dslTermDefinition, userCriteria, criteriaValue, dslMultiField);
final DslMultiExpression monoFieldMultiExpressionDefinition = new DslMultiExpression(firstNotEmpty(userCriteria.getOverridedPreModifier(), dslTermDefinition.getPreTerm()), true, monoFieldExpressionDefinitions, Collections.emptyList(), "");
appendMultiExpression(query, monoFieldMultiExpressionDefinition);
query.append(userCriteria.getPostMissingPart());
} else {
criteriaOnDefinitionField++;
query.append(userCriteria.getPreMissingPart());
if (RESERVED_QUERY_KEYWORDS.contains(criteriaValue)) {
// toUpperCase car ES n'interprete pas correctement en lowercase
query.append(criteriaValue.toUpperCase(Locale.ROOT));
} else {
appendStandardCriteriaValue(query, dslTermDefinition, userCriteria, criteriaValue);
}
query.append(userCriteria.getPostMissingPart());
}
}
// useBlock if more than 1 criteria
return criteriaOnDefinitionField > 1;
}
use of io.vertigo.dynamox.search.dsl.model.DslMultiExpression in project vertigo by KleeGroup.
the class DslListFilterBuilder method appendMultiExpression.
private void appendMultiExpression(final StringBuilder query, final DslMultiExpression multiExpressionDefinition) {
final StringBuilder multiExpressionQuery = new StringBuilder();
for (final DslExpression expression : multiExpressionDefinition.getExpressions()) {
appendExpression(multiExpressionQuery, expression);
}
for (final DslMultiExpression multiExpression : multiExpressionDefinition.getMultiExpressions()) {
appendMultiExpression(multiExpressionQuery, multiExpression);
}
flushSubQueryToQuery(query, multiExpressionDefinition.getPreBody(), multiExpressionDefinition.getPostBody(), multiExpressionDefinition.isBlock(), multiExpressionQuery);
}
Aggregations