.sort(agePropertyName, SortDirection.ASCENDING) .vertices()); assertVertexIds(vertices, "v2", "v3", "v4", "v1"); .sort(agePropertyName, SortDirection.DESCENDING) .vertices()); assertVertexIds(vertices, "v4", "v3", "v2", "v1"); .sort(namePropertyName, SortDirection.ASCENDING) .vertices()); Assert.assertEquals(4, count(vertices)); .sort(namePropertyName, SortDirection.DESCENDING) .vertices()); Assert.assertEquals(4, count(vertices)); .sort(namePropertyName, SortDirection.ASCENDING) .sort(agePropertyName, SortDirection.ASCENDING) .vertices()); .sort(namePropertyName, SortDirection.ASCENDING) .sort(agePropertyName, SortDirection.DESCENDING) .vertices()); .sort(Element.ID_PROPERTY_NAME, SortDirection.ASCENDING) .vertices()); assertVertexIds(vertices, "v1", "v2", "v3", "v4"); .sort(Element.ID_PROPERTY_NAME, SortDirection.DESCENDING)
.sort(agePropertyName, SortDirection.ASCENDING) .vertices()); assertVertexIds(vertices, "v2", "v3", "v4", "v1"); .sort(agePropertyName, SortDirection.DESCENDING) .vertices()); assertVertexIds(vertices, "v4", "v3", "v2", "v1"); .sort(namePropertyName, SortDirection.ASCENDING) .vertices()); Assert.assertEquals(4, count(vertices)); .sort(namePropertyName, SortDirection.DESCENDING) .vertices()); Assert.assertEquals(4, count(vertices)); .sort(namePropertyName, SortDirection.ASCENDING) .sort(agePropertyName, SortDirection.ASCENDING) .vertices()); .sort(namePropertyName, SortDirection.ASCENDING) .sort(agePropertyName, SortDirection.DESCENDING) .vertices()); .sort(Element.ID_PROPERTY_NAME, SortDirection.ASCENDING) .vertices()); assertVertexIds(vertices, "v1", "v2", "v3", "v4"); .sort(Element.ID_PROPERTY_NAME, SortDirection.DESCENDING)
.sort(Element.ID_PROPERTY_NAME, SortDirection.ASCENDING) .skip(0) .limit(1) .sort(Element.ID_PROPERTY_NAME, SortDirection.ASCENDING) .skip(1) .limit(1) .sort(Element.ID_PROPERTY_NAME, SortDirection.ASCENDING) .skip(2) .limit(1) assertIdsAnyOrder(idsIterable, "v3"); idsIterable = graph.query(AUTHORIZATIONS_A).sort(namePropertyName, SortDirection.ASCENDING).vertexIds(); assertResultsCount(3, 3, idsIterable); .sort(namePropertyName, SortDirection.ASCENDING) .skip(0) .limit(1)
.sort(Element.ID_PROPERTY_NAME, SortDirection.ASCENDING) .skip(0) .limit(1) .sort(Element.ID_PROPERTY_NAME, SortDirection.ASCENDING) .skip(1) .limit(1) .sort(Element.ID_PROPERTY_NAME, SortDirection.ASCENDING) .skip(2) .limit(1) assertIdsAnyOrder(idsIterable, "v3"); idsIterable = graph.query(AUTHORIZATIONS_A).sort(namePropertyName, SortDirection.ASCENDING).vertexIds(); assertResultsCount(3, 3, idsIterable); .sort(namePropertyName, SortDirection.ASCENDING) .skip(0) .limit(1)
@Test public void testGraphQuerySortOnPropertyThatHasNoValuesInTheIndex() { graph.defineProperty("age").dataType(Integer.class).sortable(true).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("name", "joe", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("name", "bob", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); QueryResultsIterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A).sort("age", SortDirection.ASCENDING).vertices(); Assert.assertEquals(2, count(vertices)); }
@Test public void testGraphQuerySortOnPropertyThatHasNoValuesInTheIndex() { graph.defineProperty("age").dataType(Integer.class).sortable(true).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("name", "joe", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("name", "bob", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); QueryResultsIterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A).sort("age", SortDirection.ASCENDING).vertices(); Assert.assertEquals(2, count(vertices)); }
@Test @Override public void testGraphQuerySortOnPropertyThatHasNoValuesInTheIndex() { super.testGraphQuerySortOnPropertyThatHasNoValuesInTheIndex(); getSearchIndex().clearCache(); QueryResultsIterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A).sort("age", SortDirection.ASCENDING).vertices(); Assert.assertEquals(2, count(vertices)); }
@Test public void testGraphQuerySortOnPropertyWhichIsFullTextAndExactMatchIndexed() { graph.defineProperty("name") .dataType(String.class) .sortable(true) .textIndexHint(TextIndexHint.EXACT_MATCH, TextIndexHint.FULL_TEXT) .define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("name", "1-2", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("name", "1-1", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v3", VISIBILITY_A) .setProperty("name", "3-1", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); QueryResultsIterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A_AND_B).sort("name", SortDirection.ASCENDING).vertices(); assertVertexIds(vertices, "v2", "v1", "v3"); vertices = graph.query("3", AUTHORIZATIONS_A_AND_B).vertices(); assertVertexIds(vertices, "v3"); vertices = graph.query("*", AUTHORIZATIONS_A_AND_B) .has("name", Compare.EQUAL, "3-1") .vertices(); assertVertexIds(vertices, "v3"); }
@Test public void testGraphQuerySortOnPropertyWhichIsFullTextAndExactMatchIndexed() { graph.defineProperty("name") .dataType(String.class) .sortable(true) .textIndexHint(TextIndexHint.EXACT_MATCH, TextIndexHint.FULL_TEXT) .define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("name", "1-2", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("name", "1-1", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v3", VISIBILITY_A) .setProperty("name", "3-1", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); QueryResultsIterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A_AND_B).sort("name", SortDirection.ASCENDING).vertices(); assertVertexIds(vertices, "v2", "v1", "v3"); vertices = graph.query("3", AUTHORIZATIONS_A_AND_B).vertices(); assertVertexIds(vertices, "v3"); vertices = graph.query("*", AUTHORIZATIONS_A_AND_B) .has("name", Compare.EQUAL, "3-1") .vertices(); assertVertexIds(vertices, "v3"); }