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