@Override public Iterable<Vertex> vertices() { if (!hasFilter) { return VertexiumBlueprintsConvert.toBlueprintsVertices(graph, graph.getGraph().getVertices(graph.getFetchHints(), authorizations), authorizations); } Iterable<org.vertexium.Vertex> vertices = q.vertices(graph.getFetchHints()); return VertexiumBlueprintsConvert.toBlueprintsVertices(graph, vertices, authorizations); } }
@Test public void testGraphQueryWithQueryString() { 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_A, 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("description", "This is edge 1 - dog to cat.", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); Iterable<Vertex> vertices = graph.query("vertex", AUTHORIZATIONS_A_AND_B).vertices(); Assert.assertEquals(2, count(vertices)); vertices = graph.query("vertex", AUTHORIZATIONS_A).vertices(); Assert.assertEquals(1, count(vertices)); vertices = graph.query("dog", AUTHORIZATIONS_A).vertices(); Assert.assertEquals(1, count(vertices)); vertices = graph.query("dog", AUTHORIZATIONS_B).vertices(); Assert.assertEquals(0, count(vertices)); Iterable<Element> elements = graph.query("dog", AUTHORIZATIONS_A_AND_B).elements(); Assert.assertEquals(2, count(elements)); }
@Test public void testGraphQueryWithQueryString() { 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_A, 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("description", "This is edge 1 - dog to cat.", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); Iterable<Vertex> vertices = graph.query("vertex", AUTHORIZATIONS_A_AND_B).vertices(); Assert.assertEquals(2, count(vertices)); vertices = graph.query("vertex", AUTHORIZATIONS_A).vertices(); Assert.assertEquals(1, count(vertices)); vertices = graph.query("dog", AUTHORIZATIONS_A).vertices(); Assert.assertEquals(1, count(vertices)); vertices = graph.query("dog", AUTHORIZATIONS_B).vertices(); Assert.assertEquals(0, count(vertices)); Iterable<Element> elements = graph.query("dog", AUTHORIZATIONS_A_AND_B).elements(); Assert.assertEquals(2, count(elements)); }
@Test public void testGraphQueryTextVertexDifferentAuths() { graph.defineProperty("title").dataType(String.class).textIndexHint(TextIndexHint.ALL).define(); graph.defineProperty("fullText").dataType(String.class).textIndexHint(TextIndexHint.FULL_TEXT).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("title", "hello", VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_B) .setProperty("fullText", StreamingPropertyValue.create("this is text with hello"), VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Iterable<Vertex> vertices = graph.query("hello", AUTHORIZATIONS_A).vertices(); assertResultsCount(1, 1, (QueryResultsIterable) vertices); vertices = graph.query("hello", AUTHORIZATIONS_A_AND_B).vertices(); assertResultsCount(2, 2, (QueryResultsIterable) vertices); }
@Test public void testGraphQueryTextVertexDifferentAuths() { graph.defineProperty("title").dataType(String.class).textIndexHint(TextIndexHint.ALL).define(); graph.defineProperty("fullText").dataType(String.class).textIndexHint(TextIndexHint.FULL_TEXT).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("title", "hello", VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_B) .setProperty("fullText", StreamingPropertyValue.create("this is text with hello"), VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Iterable<Vertex> vertices = graph.query("hello", AUTHORIZATIONS_A).vertices(); assertResultsCount(1, 1, (QueryResultsIterable) vertices); vertices = graph.query("hello", AUTHORIZATIONS_A_AND_B).vertices(); assertResultsCount(2, 2, (QueryResultsIterable) vertices); }
@Test public void testGraphQueryHasWithSpacesAndFieldedQueryString() { assumeTrue("fielded query not supported", isFieldNamesInQuerySupported()); graph.defineProperty("http://vertexium.org#name").dataType(String.class).textIndexHint(TextIndexHint.ALL).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("http://vertexium.org#name", "Joe Ferner", VISIBILITY_A) .setProperty("propWithHyphen", "hyphen-word", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("http://vertexium.org#name", "Joe Smith", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); assumeTrue("lucene queries", isLuceneQueriesSupported()); Iterable<Vertex> vertices = graph.query("http\\:\\/\\/vertexium.org#name:Joe", AUTHORIZATIONS_A) .vertices(); Assert.assertEquals(2, count(vertices)); vertices = graph.query("http\\:\\/\\/vertexium.org#name:\"Joe Ferner\"", AUTHORIZATIONS_A) .vertices(); Assert.assertEquals(1, count(vertices)); }
@Test public void testGraphQueryHasWithSpacesAndFieldedQueryString() { assumeTrue("fielded query not supported", isFieldNamesInQuerySupported()); graph.defineProperty("http://vertexium.org#name").dataType(String.class).textIndexHint(TextIndexHint.ALL).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("http://vertexium.org#name", "Joe Ferner", VISIBILITY_A) .setProperty("propWithHyphen", "hyphen-word", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("http://vertexium.org#name", "Joe Smith", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); assumeTrue("lucene queries", isLuceneQueriesSupported()); Iterable<Vertex> vertices = graph.query("http\\:\\/\\/vertexium.org#name:Joe", AUTHORIZATIONS_A) .vertices(); Assert.assertEquals(2, count(vertices)); vertices = graph.query("http\\:\\/\\/vertexium.org#name:\"Joe Ferner\"", AUTHORIZATIONS_A) .vertices(); Assert.assertEquals(1, count(vertices)); }
@Test public void testQueryReturningElasticsearchVertex() { graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A); graph.addVertex("v2", VISIBILITY_B, AUTHORIZATIONS_B); graph.addEdge("e1", "v1", "v2", LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); graph.flush(); QueryResultsIterable<Vertex> vertices = graph.query(AUTHORIZATIONS_B) .vertices(FetchHints.NONE); assertResultsCount(1, 1, vertices); Vertex vertex = toList(vertices).get(0); assertEquals("v2", vertex.getId()); }
@Test public void testGraphQueryVertexNoVisibility() { graph.prepareVertex("v1", VISIBILITY_EMPTY) .setProperty("text", "hello", VISIBILITY_EMPTY) .setProperty("age", 25, VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Iterable<Vertex> vertices = graph.query("hello", AUTHORIZATIONS_A_AND_B) .has("age", Compare.EQUAL, 25) .vertices(); Assert.assertEquals(1, count(vertices)); vertices = graph.query("hello", AUTHORIZATIONS_A_AND_B) .vertices(); Assert.assertEquals(1, count(vertices)); }
@Test public void testGraphQueryVertexNoVisibility() { graph.prepareVertex("v1", VISIBILITY_EMPTY) .setProperty("text", "hello", VISIBILITY_EMPTY) .setProperty("age", 25, VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Iterable<Vertex> vertices = graph.query("hello", AUTHORIZATIONS_A_AND_B) .has("age", Compare.EQUAL, 25) .vertices(); Assert.assertEquals(1, count(vertices)); vertices = graph.query("hello", AUTHORIZATIONS_A_AND_B) .vertices(); Assert.assertEquals(1, count(vertices)); }
@Test public void testGraphQueryWithBoolean() { graph.defineProperty("boolean").dataType(Boolean.class).define(); graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("k1", "boolean", true, VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); QueryResultsIterable<Vertex> vertices = graph.query("zzzzz", AUTHORIZATIONS_A).vertices(); assertResultsCount(0, 0, vertices); vertices = graph.query(AUTHORIZATIONS_A).has("boolean", true).vertices(); assertResultsCount(1, 1, vertices); vertices = graph.query(AUTHORIZATIONS_A).has("boolean", false).vertices(); assertResultsCount(0, 0, vertices); }
@Test public void testGraphQueryWithBoolean() { graph.defineProperty("boolean").dataType(Boolean.class).define(); graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("k1", "boolean", true, VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); QueryResultsIterable<Vertex> vertices = graph.query("zzzzz", AUTHORIZATIONS_A).vertices(); assertResultsCount(0, 0, vertices); vertices = graph.query(AUTHORIZATIONS_A).has("boolean", true).vertices(); assertResultsCount(1, 1, vertices); vertices = graph.query(AUTHORIZATIONS_A).has("boolean", false).vertices(); assertResultsCount(0, 0, vertices); }
@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)); }
@Test public void testGraphQueryWithANDOperatorAndWithExactMatchFields() { graph.defineProperty("firstName").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("firstName", "Joe", VISIBILITY_A) .setProperty("lastName", "Ferner", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("firstName", "Joe", VISIBILITY_A) .setProperty("lastName", "Smith", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); assumeTrue("lucene and queries not supported", isLuceneQueriesSupported() && isLuceneAndQueriesSupported()); Iterable<Vertex> vertices = graph.query("Joe AND ferner", AUTHORIZATIONS_A) .vertices(); Assert.assertEquals(1, count(vertices)); }
@Test public void testGraphQueryWithANDOperatorAndWithExactMatchFields() { graph.defineProperty("firstName").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("firstName", "Joe", VISIBILITY_A) .setProperty("lastName", "Ferner", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("firstName", "Joe", VISIBILITY_A) .setProperty("lastName", "Smith", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); assumeTrue("lucene and queries not supported", isLuceneQueriesSupported() && isLuceneAndQueriesSupported()); Iterable<Vertex> vertices = graph.query("Joe AND ferner", AUTHORIZATIONS_A) .vertices(); Assert.assertEquals(1, count(vertices)); }
@Test public void testFieldBoost() throws Exception { assumeTrue("Boost not supported", graph.isFieldBoostSupported()); graph.defineProperty("a") .dataType(String.class) .textIndexHint(TextIndexHint.ALL) .boost(1) .define(); graph.defineProperty("b") .dataType(String.class) .textIndexHint(TextIndexHint.ALL) .boost(2) .define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("a", "Test Value", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("b", "Test Value", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); assertVertexIds(graph.query("Test", AUTHORIZATIONS_A).vertices(), "v2", "v1"); }
@Test public void testFieldBoost() throws Exception { assumeTrue("Boost not supported", graph.isFieldBoostSupported()); graph.defineProperty("a") .dataType(String.class) .textIndexHint(TextIndexHint.ALL) .boost(1) .define(); graph.defineProperty("b") .dataType(String.class) .textIndexHint(TextIndexHint.ALL) .boost(2) .define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("a", "Test Value", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("b", "Test Value", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); assertVertexIds(graph.query("Test", AUTHORIZATIONS_A).vertices(), "v2", "v1"); }
@Test public void testQueryExecutionCountWhenScrollingApi() { Elasticsearch5SearchIndex searchIndex = (Elasticsearch5SearchIndex) ((GraphWithSearchIndex) graph).getSearchIndex(); searchIndex.getConfig().getGraphConfiguration().set(GraphConfiguration.SEARCH_INDEX_PROP_PREFIX + "." + ElasticsearchSearchIndexConfiguration.QUERY_PAGE_SIZE, 1); graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A); graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A); graph.flush(); long startingNumQueries = getNumQueries(); QueryResultsIterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A).vertices(); assertResultsCount(2, vertices); assertEquals(startingNumQueries + 4, getNumQueries()); searchIndex = (Elasticsearch5SearchIndex) ((GraphWithSearchIndex) graph).getSearchIndex(); searchIndex.getConfig().getGraphConfiguration().set(GraphConfiguration.SEARCH_INDEX_PROP_PREFIX + "." + ElasticsearchSearchIndexConfiguration.QUERY_PAGE_SIZE, 2); graph.addVertex("v3", VISIBILITY_A, AUTHORIZATIONS_A); graph.flush(); vertices = graph.query(AUTHORIZATIONS_A).vertices(); assertResultsCount(3, vertices); assertEquals(startingNumQueries + 8, getNumQueries()); }
@Test public void testQueryExecutionCountWhenPaging() { graph.prepareVertex("v1", VISIBILITY_A).save(AUTHORIZATIONS_A); graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A); graph.flush(); long startingNumQueries = getNumQueries(); QueryResultsIterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A).vertices(); assertEquals(startingNumQueries, getNumQueries()); assertResultsCount(2, 2, vertices); assertEquals(startingNumQueries + 2, getNumQueries()); vertices = graph.query(AUTHORIZATIONS_A).limit(1).vertices(); assertEquals(startingNumQueries + 4, getNumQueries()); assertResultsCount(1, 2, vertices); assertEquals(startingNumQueries + 4, getNumQueries()); vertices = graph.query(AUTHORIZATIONS_A).limit(10).vertices(); assertEquals(startingNumQueries + 6, getNumQueries()); assertResultsCount(2, 2, vertices); assertEquals(startingNumQueries + 6, getNumQueries()); }