@NonNull private Item buildPredicate(OperatorNode<ExpressionOperator> ast) { List<OperatorNode<ExpressionOperator>> args = ast.getArgument(1); Preconditions.checkArgument(args.size() == 3, "Expected 3 arguments, got %s.", args.size()); PredicateQueryItem item = new PredicateQueryItem(); item.setIndexName(getIndex(args.get(0))); addFeatures(args.get(1), (key, value, subqueryBitmap) -> item.addFeature(key, (String) value, subqueryBitmap), PredicateQueryItem.ALL_SUB_QUERIES); addFeatures(args.get(2), (key, value, subqueryBitmap) -> { if (value instanceof Long) { item.addRangeFeature(key, (Long) value, subqueryBitmap); } else { item.addRangeFeature(key, (Integer) value, subqueryBitmap); } }, PredicateQueryItem.ALL_SUB_QUERIES); return leafStyleSettings(ast, item); }
@NonNull private Item buildPredicate(String key, Inspector value) { HashMap<Integer, Inspector> children = getChildrenMap(value); String field = children.get(0).asString(); Inspector args = children.get(1); Preconditions.checkArgument(children.size() == 3, "Expected 3 arguments, got %s.", children.size()); PredicateQueryItem item = new PredicateQueryItem(); item.setIndexName(field); List<Inspector> argumentList = valueListFromInspector(getChildren(value)); // Adding attributes argumentList.get(1).traverse((ObjectTraverser) (attrKey, attrValue) -> { if (attrValue.type() == ARRAY){ List<Inspector> attributes = valueListFromInspector(attrValue); attributes.forEach( (attribute) -> item.addFeature(attrKey, attribute.asString())); } else { item.addFeature(attrKey, attrValue.asString()); } }); // Adding range attributes argumentList.get(2).traverse((ObjectTraverser) (attrKey, attrValue) -> item.addRangeFeature(attrKey, (int)attrValue.asDouble())); return leafStyleSettings(getAnnotations(value), item); }
private void addPredicateTerm(Query query, String fieldName, String attributes, String rangeAttributes) { PredicateQueryItem item = new PredicateQueryItem(); item.setIndexName(fieldName); new PredicateValueAttributeParser(item).parse(attributes); new PredicateRangeAttributeParser(item).parse(rangeAttributes); QueryTreeUtil.andQueryItemWithRoot(query, item); }