@Override public long getTotalHits() { long total = 0; for (Iterable<? extends T> iterable : getIterables()) { if (iterable instanceof IterableWithTotalHits) { total += ((IterableWithTotalHits) iterable).getTotalHits(); } } return total; } }
@Override public long getTotalHits() { long total = 0; for (Iterable<? extends T> iterable : getIterables()) { if (iterable instanceof IterableWithTotalHits) { total += ((IterableWithTotalHits) iterable).getTotalHits(); } } return total; } }
private static long getTotalHits( VertexiumCypherQueryContext ctx, MatchConstraint<?, ?> matchConstraint, ExpressionScope scope ) { return ctx.getTotalHitsForMatchConstraint( matchConstraint, mc -> executeFirstMatchConstraint(ctx, mc, scope, 0L).getTotalHits() ); }
private static long getTotalHits( VertexiumCypherQueryContext ctx, MatchConstraint<?, ?> matchConstraint, ExpressionScope scope ) { return ctx.getTotalHitsForMatchConstraint( matchConstraint, mc -> executeFirstMatchConstraint(ctx, mc, scope, 0L).getTotalHits() ); }
public static void assertResultsCount( int expectedCount, int expectedTotalHits, IterableWithTotalHits<?> results ) { assertEquals(expectedTotalHits, results.getTotalHits()); assertCount(expectedCount, results); }
public static void assertResultsCount( int expectedCount, int expectedTotalHits, IterableWithTotalHits<?> results ) { assertEquals(expectedTotalHits, results.getTotalHits()); assertCount(expectedCount, results); }
@Test public void testGraphQueryHasGeoPointAndExact() { graph.defineProperty("location").dataType(GeoPoint.class).define(); graph.defineProperty("exact").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("prop1", "val1", VISIBILITY_A) .setProperty("exact", "val1", VISIBILITY_A) .setProperty("location", new GeoPoint(38.9186, -77.2297), VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("prop2", "val2", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Iterable<Element> results = graph.query("*", AUTHORIZATIONS_A_AND_B).has("prop1").elements(); assertEquals(1, count(results)); assertEquals(1, ((IterableWithTotalHits) results).getTotalHits()); assertEquals("v1", results.iterator().next().getId()); results = graph.query("*", AUTHORIZATIONS_A_AND_B).has("exact").elements(); assertEquals(1, count(results)); assertEquals(1, ((IterableWithTotalHits) results).getTotalHits()); assertEquals("v1", results.iterator().next().getId()); results = graph.query("*", AUTHORIZATIONS_A_AND_B).has("location").elements(); assertEquals(1, count(results)); assertEquals(1, ((IterableWithTotalHits) results).getTotalHits()); assertEquals("v1", results.iterator().next().getId()); }
@Test public void testGraphQueryHasGeoPointAndExact() { graph.defineProperty("location").dataType(GeoPoint.class).define(); graph.defineProperty("exact").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("prop1", "val1", VISIBILITY_A) .setProperty("exact", "val1", VISIBILITY_A) .setProperty("location", new GeoPoint(38.9186, -77.2297), VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("prop2", "val2", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Iterable<Element> results = graph.query("*", AUTHORIZATIONS_A_AND_B).has("prop1").elements(); assertEquals(1, count(results)); assertEquals(1, ((IterableWithTotalHits) results).getTotalHits()); assertEquals("v1", results.iterator().next().getId()); results = graph.query("*", AUTHORIZATIONS_A_AND_B).has("exact").elements(); assertEquals(1, count(results)); assertEquals(1, ((IterableWithTotalHits) results).getTotalHits()); assertEquals("v1", results.iterator().next().getId()); results = graph.query("*", AUTHORIZATIONS_A_AND_B).has("location").elements(); assertEquals(1, count(results)); assertEquals(1, ((IterableWithTotalHits) results).getTotalHits()); assertEquals("v1", results.iterator().next().getId()); }
assertEquals(1, ((IterableWithTotalHits) results).getTotalHits()); assertEquals("v2", results.iterator().next().getId()); assertEquals(1, ((IterableWithTotalHits) results).getTotalHits()); assertEquals("v2", results.iterator().next().getId()); assertEquals(1, ((IterableWithTotalHits) results).getTotalHits()); assertEquals("v2", results.iterator().next().getId());
assertEquals(1, ((IterableWithTotalHits) results).getTotalHits()); assertEquals("v2", results.iterator().next().getId()); assertEquals(1, ((IterableWithTotalHits) results).getTotalHits()); assertEquals("v2", results.iterator().next().getId()); assertEquals(1, ((IterableWithTotalHits) results).getTotalHits()); assertEquals("v2", results.iterator().next().getId());
Assert.assertEquals(1, count(vertices)); if (vertices instanceof IterableWithTotalHits) { Assert.assertEquals(1, ((IterableWithTotalHits) vertices).getTotalHits()); Assert.assertEquals(0, count(vertices)); // need auth A to see the v2 node itself if (vertices instanceof IterableWithTotalHits) { Assert.assertEquals(0, ((IterableWithTotalHits) vertices).getTotalHits()); Assert.assertEquals(2, count(vertices)); if (vertices instanceof IterableWithTotalHits) { Assert.assertEquals(2, ((IterableWithTotalHits) vertices).getTotalHits());
Assert.assertEquals(1, count(vertices)); if (vertices instanceof IterableWithTotalHits) { Assert.assertEquals(1, ((IterableWithTotalHits) vertices).getTotalHits()); Assert.assertEquals(0, count(vertices)); // need auth A to see the v2 node itself if (vertices instanceof IterableWithTotalHits) { Assert.assertEquals(0, ((IterableWithTotalHits) vertices).getTotalHits()); Assert.assertEquals(2, count(vertices)); if (vertices instanceof IterableWithTotalHits) { Assert.assertEquals(2, ((IterableWithTotalHits) vertices).getTotalHits());
@Test public void testGraphQueryIn() { String namePropertyName = "full.name"; graph.defineProperty("age").dataType(Integer.class).sortable(true).define(); graph.defineProperty(namePropertyName).dataType(String.class).sortable(true).textIndexHint(TextIndexHint.ALL).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty(namePropertyName, "joe ferner", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty(namePropertyName, "bob smith", VISIBILITY_B) .setProperty("age", 25, VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v3", VISIBILITY_A) .setProperty(namePropertyName, "tom thumb", VISIBILITY_A) .setProperty("age", 30, VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); List<String> strings = new ArrayList<>(); strings.add("joe ferner"); strings.add("tom thumb"); Iterable<Vertex> results = graph.query(AUTHORIZATIONS_A_AND_B).has(namePropertyName, Contains.IN, strings).vertices(); assertEquals(2, ((IterableWithTotalHits) results).getTotalHits()); assertVertexIdsAnyOrder(results, "v1", "v3"); }
@Test public void testGraphQueryIn() { String namePropertyName = "full.name"; graph.defineProperty("age").dataType(Integer.class).sortable(true).define(); graph.defineProperty(namePropertyName).dataType(String.class).sortable(true).textIndexHint(TextIndexHint.ALL).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty(namePropertyName, "joe ferner", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty(namePropertyName, "bob smith", VISIBILITY_B) .setProperty("age", 25, VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v3", VISIBILITY_A) .setProperty(namePropertyName, "tom thumb", VISIBILITY_A) .setProperty("age", 30, VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); List<String> strings = new ArrayList<>(); strings.add("joe ferner"); strings.add("tom thumb"); Iterable<Vertex> results = graph.query(AUTHORIZATIONS_A_AND_B).has(namePropertyName, Contains.IN, strings).vertices(); assertEquals(2, ((IterableWithTotalHits) results).getTotalHits()); assertVertexIdsAnyOrder(results, "v1", "v3"); }
@Test public void testGraphQueryWithQueryStringWithAuthorizations() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_ALL); v1.setProperty("description", "This is vertex 1 - dog.", VISIBILITY_A, AUTHORIZATIONS_ALL); Vertex v2 = graph.addVertex("v2", VISIBILITY_B, AUTHORIZATIONS_ALL); v2.setProperty("description", "This is vertex 2 - cat.", VISIBILITY_B, AUTHORIZATIONS_ALL); Edge e1 = graph.addEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); e1.setProperty("edgeDescription", "This is edge 1 - dog to cat.", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); Iterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A).vertices(); assertEquals(1, count(vertices)); if (isIterableWithTotalHitsSupported(vertices)) { IterableWithTotalHits hits = (IterableWithTotalHits) vertices; assertEquals(1, hits.getTotalHits()); } Iterable<Edge> edges = graph.query(AUTHORIZATIONS_A).edges(); assertEquals(1, count(edges)); }
@Test public void testGraphQueryWithQueryStringWithAuthorizations() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_ALL); v1.setProperty("description", "This is vertex 1 - dog.", VISIBILITY_A, AUTHORIZATIONS_ALL); Vertex v2 = graph.addVertex("v2", VISIBILITY_B, AUTHORIZATIONS_ALL); v2.setProperty("description", "This is vertex 2 - cat.", VISIBILITY_B, AUTHORIZATIONS_ALL); Edge e1 = graph.addEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); e1.setProperty("edgeDescription", "This is edge 1 - dog to cat.", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); Iterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A).vertices(); assertEquals(1, count(vertices)); if (isIterableWithTotalHitsSupported(vertices)) { IterableWithTotalHits hits = (IterableWithTotalHits) vertices; assertEquals(1, hits.getTotalHits()); } Iterable<Edge> edges = graph.query(AUTHORIZATIONS_A).edges(); assertEquals(1, count(edges)); }
org.vertexium.test.util.IterableUtils.assertContains(v3, vertices); if (isIterableWithTotalHitsSupported(vertices)) { Assert.assertEquals(2, ((IterableWithTotalHits) vertices).getTotalHits()); Assert.assertEquals(2, ((IterableWithTotalHits) vertices).getTotalHits());
org.vertexium.test.util.IterableUtils.assertContains(v3, vertices); if (isIterableWithTotalHitsSupported(vertices)) { Assert.assertEquals(2, ((IterableWithTotalHits) vertices).getTotalHits()); Assert.assertEquals(2, ((IterableWithTotalHits) vertices).getTotalHits());