@Test public void regex_on_field_partial_string_match_works() throws Exception { QueryExpression q = EvalTestContext.queryExpressionFromJson("{'field':'field1','regex':'val.*'}"); QueryEvaluator qe = QueryEvaluator.getInstance(q, md); QueryEvaluationContext ctx = qe.evaluate(jsonDoc); Assert.assertTrue(ctx.getResult()); }
@Override public boolean evaluate(QueryEvaluationContext ctx) { LOGGER.debug("evaluate {} {}", relativePath, regex); KeyValueCursor<Path, JsonNode> cursor = ctx.getNodes(relativePath); boolean ret = false; while (cursor.hasNext()) { cursor.next(); JsonNode valueNode = cursor.getCurrentValue(); Object docValue; if (valueNode != null) { docValue = fieldMd.getType().fromJson(valueNode); } else { docValue = null; } LOGGER.debug(" value={}", valueNode); if (docValue != null) { ret = regex.matcher(docValue.toString()).matches(); } if (ret) { break; } } ctx.setResult(ret); return ret; }
RegexEvaluator extends QueryEvaluator { @Override public boolean evaluate(QueryEvaluationContext ctx) { LOGGER.debug("evaluate {} {}", relativePath, regex); KeyValueCursor<Path, JsonNode> cursor = ctx.getNodes(relativePath); boolean ret = false; while (cursor.hasNext()) { cursor.next(); JsonNode valueNode = cursor.getCurrentValue(); Object docValue; if (valueNode != null) { docValue = fieldMd.getType().fromJson(valueNode); } else { docValue = null; } LOGGER.debug(" value={}", valueNode); if (docValue != null) { ret = regex.matcher(docValue.toString()).matches(); } if (ret) { break; } } ctx.setResult(ret); return ret; } }
RegexEvaluator extends QueryEvaluator { @Override public boolean evaluate(QueryEvaluationContext ctx) { LOGGER.debug("evaluate {} {}", relativePath, regex); KeyValueCursor<Path, JsonNode> cursor = ctx.getNodes(relativePath); boolean ret = false; while (cursor.hasNext()) { cursor.next(); JsonNode valueNode = cursor.getCurrentValue(); Object docValue; if (valueNode != null) { docValue = fieldMd.getType().fromJson(valueNode); } else { docValue = null; } LOGGER.debug(" value={}", valueNode); if (docValue != null) { ret = regex.matcher(docValue.toString()).matches(); } if (ret) { break; } } ctx.setResult(ret); return ret; } RegexEvaluator(RegexMatchExpression expr, FieldTreeNode context); }
RegexEvaluator extends QueryEvaluator { @Override public boolean evaluate(QueryEvaluationContext ctx) { LOGGER.debug("evaluate {} {}", relativePath, regex); KeyValueCursor<Path, JsonNode> cursor = ctx.getNodes(relativePath); boolean ret = false; while (cursor.hasNext()) { cursor.next(); JsonNode valueNode = cursor.getCurrentValue(); Object docValue; if (valueNode != null) { docValue = fieldMd.getType().fromJson(valueNode); } else { docValue = null; } LOGGER.debug(" value={}", valueNode); if (docValue != null) { ret = regex.matcher(docValue.toString()).matches(); } if (ret) { break; } } ctx.setResult(ret); return ret; } RegexEvaluator(RegexMatchExpression expr, FieldTreeNode context); @Override boolean evaluate(QueryEvaluationContext ctx); }
RegexEvaluator extends QueryEvaluator { @Override public boolean evaluate(QueryEvaluationContext ctx) { LOGGER.debug("evaluate {} {}", relativePath, regex); KeyValueCursor<Path, JsonNode> cursor = ctx.getNodes(relativePath); boolean ret = false; while (cursor.hasNext()) { cursor.next(); JsonNode valueNode = cursor.getCurrentValue(); Object docValue; if (valueNode != null) { docValue = fieldMd.getType().fromJson(valueNode); } else { docValue = null; } LOGGER.debug(" value={}", valueNode); if (docValue != null) { ret = regex.matcher(docValue.toString()).matches(); } if (ret) { break; } } ctx.setResult(ret); return ret; } RegexEvaluator(RegexMatchExpression expr, FieldTreeNode context); @Override boolean evaluate(QueryEvaluationContext ctx);  }