Search in sources :

Example 1 with DslUserCriteria

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

the class DslUserCriteriaRule method parse.

/**
 * @param userString User string
 * @return Parsed list of DslUserCriteria
 */
static List<DslUserCriteria> parse(final String userString) {
    final List<DslUserCriteria> userCriteria = new ArrayList<>();
    // split space chars to add preModifier and postModifier
    final Matcher criteriaValueMatcher = CRITERIA_VALUE_PATTERN.matcher(userString);
    while (criteriaValueMatcher.find()) {
        final String preMissingPart = DslUtil.nullToEmpty(criteriaValueMatcher.group(1));
        final String postMissingPart = criteriaValueMatcher.group(22);
        // les capturing groups matchs par group de 4, on cherche le premier qui match 4 par 4
        // on se base sur le overridedPreModifier qui n'est jamais null mais vide si match
        int foundGroup = 2;
        for (int i = 0; i < criteriaValueMatcher.groupCount() / 4; i++) {
            if (criteriaValueMatcher.group(i * 4 + 3) != null) {
                foundGroup = i * 4 + 2;
                // found !!
                break;
            }
        }
        final String overridedFieldName = DslUtil.nullToEmpty(criteriaValueMatcher.group(foundGroup));
        final String overridedPreModifier = DslUtil.nullToEmpty(criteriaValueMatcher.group(foundGroup + 1));
        final String criteriaValue = DslUtil.nullToEmpty(criteriaValueMatcher.group(foundGroup + 2));
        final String overridedPostModifier = DslUtil.nullToEmpty(criteriaValueMatcher.group(foundGroup + 3));
        userCriteria.add(new DslUserCriteria(preMissingPart, overridedFieldName, overridedPreModifier, criteriaValue, overridedPostModifier, postMissingPart));
    }
    return userCriteria;
}
Also used : Matcher(java.util.regex.Matcher) DslUserCriteria(io.vertigo.dynamox.search.dsl.model.DslUserCriteria) ArrayList(java.util.ArrayList)

Example 2 with DslUserCriteria

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

DslUserCriteria (io.vertigo.dynamox.search.dsl.model.DslUserCriteria)2 ArrayList (java.util.ArrayList)2 DslMultiExpression (io.vertigo.dynamox.search.dsl.model.DslMultiExpression)1 DslMultiField (io.vertigo.dynamox.search.dsl.model.DslMultiField)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1