Search in sources :

Example 1 with DslQuery

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

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

the class DslListFilterBuilder method appendMultiQuery.

private void appendMultiQuery(final StringBuilder query, final DslBlockQuery dslMultiQueryDefinition, final DslExpression expressionDefinition, final StringBuilder parentQuery) {
    final StringBuilder expressionMultiQuery = new StringBuilder();
    for (final DslQuery dslQuery : dslMultiQueryDefinition.getQueries()) {
        appendQuery(parentQuery, expressionDefinition, expressionMultiQuery, dslQuery);
    }
    flushSubQueryToQuery(query, dslMultiQueryDefinition.getPreBody(), dslMultiQueryDefinition.getPostBody(), true, expressionMultiQuery);
}
Also used : DslQuery(io.vertigo.dynamox.search.dsl.model.DslQuery)

Example 3 with DslQuery

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

the class DslListFilterBuilder method appendExpression.

private void appendExpression(final StringBuilder query, final DslExpression expressionDefinition) {
    final StringBuilder expressionQuery = new StringBuilder();
    final DslQuery dslQuery = expressionDefinition.getQuery();
    appendQuery(query, expressionDefinition, expressionQuery, dslQuery);
    flushExpressionToQuery(query, expressionDefinition, expressionQuery);
}
Also used : DslQuery(io.vertigo.dynamox.search.dsl.model.DslQuery)

Example 4 with DslQuery

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

the class DslListFilterBuilder method appendRangeQuery.

private void appendRangeQuery(final StringBuilder query, final DslRangeQuery dslQuery, final DslExpression expressionDefinition) {
    final DslQuery startQueryDefinition = dslQuery.getStartQueryDefinitions();
    final DslQuery endQueryDefinition = dslQuery.getEndQueryDefinitions();
    final StringBuilder startRangeQuery = new StringBuilder();
    if (startQueryDefinition instanceof DslTermQuery) {
        // null because, can't use upper output
        appendTermQuery(startRangeQuery, (DslTermQuery) startQueryDefinition, expressionDefinition, null);
    } else if (startQueryDefinition instanceof DslFixedQuery) {
        appendFixedQuery(startRangeQuery, (DslFixedQuery) startQueryDefinition);
    }
    final StringBuilder endRangeQuery = new StringBuilder();
    if (endQueryDefinition instanceof DslTermQuery) {
        // null because, can't use upper output
        appendTermQuery(endRangeQuery, (DslTermQuery) endQueryDefinition, expressionDefinition, null);
    } else if (endQueryDefinition instanceof DslFixedQuery) {
        appendFixedQuery(endRangeQuery, (DslFixedQuery) endQueryDefinition);
    }
    // flush Range Query
    final String startRangeStr = startRangeQuery.length() > 0 ? startRangeQuery.toString() : "*";
    final String endRangeStr = endRangeQuery.length() > 0 ? endRangeQuery.toString() : "*";
    if (!"*".equals(startRangeStr) || !"*".equals(endRangeStr)) {
        query.append(dslQuery.getPreBody()).append(dslQuery.getStartRange()).append(startRangeStr).append(// toUpperCase car ES n'interprete pas correctement en lowercase
        " TO ").append(endRangeStr).append(dslQuery.getEndRange()).append(dslQuery.getPostBody());
    }
}
Also used : DslFixedQuery(io.vertigo.dynamox.search.dsl.model.DslFixedQuery) DslTermQuery(io.vertigo.dynamox.search.dsl.model.DslTermQuery) DslQuery(io.vertigo.dynamox.search.dsl.model.DslQuery)

Example 5 with DslQuery

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

the class DslRangeQueryRule method handle.

/**
 * {@inheritDoc}
 */
@Override
protected DslRangeQuery handle(final List<Object> parsing) {
    final String preQuery = (String) parsing.get(0);
    final PegChoice startChoice = (PegChoice) parsing.get(1);
    final PegChoice startTermQuery = (PegChoice) parsing.get(2);
    final DslQuery startQueryDefinitions;
    if (startTermQuery.getChoiceIndex() == 0) {
        startQueryDefinitions = new DslFixedQuery("*");
    } else {
        startQueryDefinitions = (DslQuery) startTermQuery.getValue();
    }
    final PegChoice endTermQuery = (PegChoice) parsing.get(6);
    final DslQuery endQueryDefinitions;
    if (endTermQuery.getChoiceIndex() == 0) {
        endQueryDefinitions = new DslFixedQuery("*");
    } else {
        endQueryDefinitions = (DslQuery) endTermQuery.getValue();
    }
    final PegChoice endChoice = (PegChoice) parsing.get(8);
    final String postQuery = (String) parsing.get(9);
    final String startRange = (String) startChoice.getValue();
    final String endRange = (String) endChoice.getValue();
    return new DslRangeQuery(preQuery, startRange, startQueryDefinitions, endQueryDefinitions, endRange, postQuery);
}
Also used : DslFixedQuery(io.vertigo.dynamox.search.dsl.model.DslFixedQuery) DslRangeQuery(io.vertigo.dynamox.search.dsl.model.DslRangeQuery) PegChoice(io.vertigo.commons.peg.PegChoice) DslQuery(io.vertigo.dynamox.search.dsl.model.DslQuery)

Aggregations

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