Search in sources :

Example 1 with DslField

use of io.vertigo.dynamox.search.dsl.model.DslField in project vertigo by KleeGroup.

the class DslExpressionRule method handle.

/**
 * {@inheritDoc}
 */
@Override
protected DslExpression handle(final List<Object> parsing) {
    String preExpression = ((Optional<String>) parsing.get(0)).orElse("") + parsing.get(1);
    final String postExpression;
    final Optional<DslField> field;
    final Optional<DslMultiField> multiField;
    final PegChoice fields = (PegChoice) parsing.get(2);
    switch(fields.getChoiceIndex()) {
        case 0:
            field = Optional.of((DslField) fields.getValue());
            multiField = Optional.empty();
            postExpression = "";
            break;
        case 1:
            final List<Object> multiFieldParsing = (List<Object>) fields.getValue();
            preExpression = DslUtil.concat(preExpression, (String) multiFieldParsing.get(0));
            multiField = Optional.of((DslMultiField) multiFieldParsing.get(1));
            postExpression = (String) multiFieldParsing.get(2);
            field = Optional.empty();
            break;
        default:
            throw new IllegalArgumentException("case " + fields.getChoiceIndex() + " not implemented");
    }
    final PegChoice queries = (PegChoice) parsing.get(4);
    final DslQuery query = (DslQuery) queries.getValue();
    return new DslExpression(preExpression, field, multiField, query, postExpression);
}
Also used : DslMultiField(io.vertigo.dynamox.search.dsl.model.DslMultiField) DslExpression(io.vertigo.dynamox.search.dsl.model.DslExpression) List(java.util.List) DslField(io.vertigo.dynamox.search.dsl.model.DslField) PegChoice(io.vertigo.commons.peg.PegChoice) DslQuery(io.vertigo.dynamox.search.dsl.model.DslQuery)

Example 2 with DslField

use of io.vertigo.dynamox.search.dsl.model.DslField in project vertigo by KleeGroup.

the class DslMultiFieldRule method handle.

/**
 * {@inheritDoc}
 */
@Override
protected DslMultiField handle(final List<Object> parsing) {
    // (String) parsing.get(0);
    final String preMultiField = "";
    final List<DslField> fields = new ArrayList<>();
    // ---
    // On récupère le premier mot qui est obligatoire.
    final DslField firstField = (DslField) parsing.get(2);
    fields.add(firstField);
    // On récupère le produit de la règle many
    final List<List<Object>> many = (List<List<Object>>) parsing.get(3);
    for (final List<Object> row : many) {
        fields.add((DslField) row.get(3));
    }
    // ---
    // (String) parsing.get(7);
    final String postMultiField = "";
    return new DslMultiField(preMultiField, fields, postMultiField);
}
Also used : DslMultiField(io.vertigo.dynamox.search.dsl.model.DslMultiField) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) DslField(io.vertigo.dynamox.search.dsl.model.DslField)

Example 3 with DslField

use of io.vertigo.dynamox.search.dsl.model.DslField in project vertigo by KleeGroup.

the class DslListFilterBuilder method appendCompactFields.

private void appendCompactFields(final StringBuilder query, final DslExpression expressionDefinition, final StringBuilder expressionQuery, final DslQuery dslQuery) {
    String expressionSep = "";
    final DslMultiField dslMultiField = expressionDefinition.getMultiField().get();
    for (final DslField dslField : dslMultiField.getFields()) {
        final DslField monoFieldDefinition = new DslField(firstNotEmpty(dslField.getPreBody(), dslMultiField.getPreBody()), dslField.getFieldName(), firstNotEmpty(dslField.getPostBody(), dslMultiField.getPostBody()));
        final DslExpression monoFieldExpressionDefinition = new DslExpression(concat(expressionSep, expressionDefinition.getPreBody()), Optional.of(monoFieldDefinition), Optional.empty(), dslQuery, expressionDefinition.getPostBody());
        appendTermQuery(expressionQuery, (DslTermQuery) dslQuery, monoFieldExpressionDefinition, query);
        flushExpressionToQuery(query, monoFieldExpressionDefinition, expressionQuery);
        expressionSep = " ";
    }
}
Also used : DslMultiField(io.vertigo.dynamox.search.dsl.model.DslMultiField) DslExpression(io.vertigo.dynamox.search.dsl.model.DslExpression) DslField(io.vertigo.dynamox.search.dsl.model.DslField)

Example 4 with DslField

use of io.vertigo.dynamox.search.dsl.model.DslField in project vertigo by KleeGroup.

the class DslListFilterBuilder method flattenMultiToMonoFieldExpressionDefinition.

private static List<DslExpression> flattenMultiToMonoFieldExpressionDefinition(final DslTermQuery dslTermDefinition, final DslUserCriteria userCriteria, final String criteriaValue, final DslMultiField dslMultiField) {
    final List<DslExpression> monoFieldExpressionDefinitions = new ArrayList<>();
    for (final DslField dslField : dslMultiField.getFields()) {
        final DslField monoFieldDefinition = new DslField(firstNotEmpty(dslField.getPreBody(), dslMultiField.getPreBody()), dslField.getFieldName(), "");
        final DslExpression monoFieldExpressionDefinition = new DslExpression(monoFieldExpressionDefinitions.isEmpty() ? "" : " ", Optional.of(monoFieldDefinition), Optional.empty(), new DslFixedQuery(concat(criteriaValue, firstNotEmpty(userCriteria.getOverridedPostModifier(), dslTermDefinition.getPostTerm()))), firstNotEmpty(dslField.getPostBody(), dslMultiField.getPostBody()));
        monoFieldExpressionDefinitions.add(monoFieldExpressionDefinition);
    }
    return monoFieldExpressionDefinitions;
}
Also used : DslFixedQuery(io.vertigo.dynamox.search.dsl.model.DslFixedQuery) DslExpression(io.vertigo.dynamox.search.dsl.model.DslExpression) ArrayList(java.util.ArrayList) DslField(io.vertigo.dynamox.search.dsl.model.DslField)

Aggregations

DslField (io.vertigo.dynamox.search.dsl.model.DslField)4 DslExpression (io.vertigo.dynamox.search.dsl.model.DslExpression)3 DslMultiField (io.vertigo.dynamox.search.dsl.model.DslMultiField)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 PegChoice (io.vertigo.commons.peg.PegChoice)1 DslFixedQuery (io.vertigo.dynamox.search.dsl.model.DslFixedQuery)1 DslQuery (io.vertigo.dynamox.search.dsl.model.DslQuery)1