Search in sources :

Example 1 with DslMultiField

use of io.vertigo.dynamox.search.dsl.model.DslMultiField 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 DslMultiField

use of io.vertigo.dynamox.search.dsl.model.DslMultiField 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 DslMultiField

use of io.vertigo.dynamox.search.dsl.model.DslMultiField 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 DslMultiField

use of io.vertigo.dynamox.search.dsl.model.DslMultiField 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;
}
Also used : DslMultiField(io.vertigo.dynamox.search.dsl.model.DslMultiField) DslMultiExpression(io.vertigo.dynamox.search.dsl.model.DslMultiExpression) DslUserCriteria(io.vertigo.dynamox.search.dsl.model.DslUserCriteria) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

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