Search in sources :

Example 1 with DslTermQuery

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

the class DslTermQueryRule method handle.

/**
 * {@inheritDoc}
 */
@Override
protected DslTermQuery handle(final List<Object> parsing) {
    final String preSpaces = (String) parsing.get(0);
    final String preQuery = (String) parsing.get(1);
    final List<Object> term = (List<Object>) parsing.get(2);
    final String preTerm = (String) term.get(1);
    final String termField = (String) term.get(2);
    final String postTerm = (String) term.get(3);
    final Optional<PegChoice> escapeRule = (Optional<PegChoice>) term.get(5);
    final EscapeMode escapeMode;
    if (escapeRule.isPresent()) {
        switch(escapeRule.get().getChoiceIndex()) {
            case 0:
                escapeMode = EscapeMode.remove;
                break;
            case 1:
                escapeMode = EscapeMode.escape;
                break;
            default:
                throw new IllegalArgumentException("case " + escapeRule.get().getChoiceIndex() + " not implemented");
        }
    } else {
        escapeMode = EscapeMode.none;
    }
    final Optional<List<Object>> defaultRuleOpt = (Optional<List<Object>>) term.get(6);
    final Optional<String> defaultValue = defaultRuleOpt.map(defaultRule -> (String) defaultRule.get(1));
    final String postQuery = (String) parsing.get(3);
    // final String postSpaces = (String) parsing.get(4);
    return new DslTermQuery(DslUtil.concat(preSpaces, preQuery), preTerm, termField, postTerm, escapeMode, defaultValue, postQuery);
}
Also used : Optional(java.util.Optional) EscapeMode(io.vertigo.dynamox.search.dsl.model.DslTermQuery.EscapeMode) List(java.util.List) DslTermQuery(io.vertigo.dynamox.search.dsl.model.DslTermQuery) PegChoice(io.vertigo.commons.peg.PegChoice)

Example 2 with DslTermQuery

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

Aggregations

DslTermQuery (io.vertigo.dynamox.search.dsl.model.DslTermQuery)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 EscapeMode (io.vertigo.dynamox.search.dsl.model.DslTermQuery.EscapeMode)1 List (java.util.List)1 Optional (java.util.Optional)1