return query;
}
@Override
ObjectNode toJson() {
final ObjectNode obj = mapper.createObjectNode();
final ObjectNode twig = obj.putObject(TwigPropertyParser.TWIG_PROPERTY);
if (hasRoot) {
twig.put(RootPropertyParser.ROOT_PROPERTY, rootBooleanExpression);
}
if (this.hasLevel()) {
twig.put(LevelPropertyParser.LEVEL_PROPERTY, this.getLevel());
}
if (this.hasRange()) {
final ArrayNode array = twig.putArray(RangePropertyParser.RANGE_PROPERTY);
array.add(this.getLowerBound());
array.add(this.getUpperBound());
}
if (this.hasBoost()) {
twig.put(BoostPropertyParser.BOOST_PROPERTY, this.getBoost());
}
ArrayNode childArray = null;
ArrayNode descendantArray = null;
for (final QueryClause clause : clauses) {
if (clause instanceof BasicQueryClause) {
if (!twig.has(ChildPropertyParser.CHILD_PROPERTY)) { // avoid to create an empty array in the JSON
childArray = twig.putArray(ChildPropertyParser.CHILD_PROPERTY);
}
final ObjectNode e = childArray.addObject();
e.put(OccurPropertyParser.OCCUR_PROPERTY, clause.getOccur().toString());
e.putAll(clause.getQuery().toJson());
}
else {
if (!twig.has(DescendantPropertyParser.DESCENDANT_PROPERTY)) { // avoid to create an empty array in the JSON
descendantArray = twig.putArray(DescendantPropertyParser.DESCENDANT_PROPERTY);
}
final ObjectNode e = descendantArray.addObject();
e.put(OccurPropertyParser.OCCUR_PROPERTY, clause.getOccur().toString());
e.put(LevelPropertyParser.LEVEL_PROPERTY, ((DescendantQueryClause) clause).getLevel());
e.putAll(clause.getQuery().toJson());
}
}
return obj;
}