@Override public Iterable<User> find(int skip, int limit) { QueryResultsIterable<Vertex> userVertices = graph.query(authorizations) .has(VisalloProperties.CONCEPT_TYPE.getPropertyName(), userConceptId) .skip(skip) .limit(limit) .vertices(); return new ConvertingIterable<Vertex, User>(userVertices) { @Override protected User convert(Vertex vertex) { return createFromVertex(vertex); } }; }
@Override public Iterable<User> findByStatus(int skip, int limit, UserStatus status) { QueryResultsIterable<Vertex> userVertices = graph.query(authorizations) .has(VisalloProperties.CONCEPT_TYPE.getPropertyName(), userConceptId) .has(UserVisalloProperties.STATUS.getPropertyName(), status.toString()) .skip(skip) .limit(limit) .vertices(); return new ConvertingIterable<Vertex, User>(userVertices) { @Override protected User convert(Vertex vertex) { return createFromVertex(vertex); } }; }
public JSONObject getAverages(int minutes, Graph graph, Authorizations authorizations) { Date minutesAgo = new Date(System.currentTimeMillis() - minutes * 60 * 1000); Query q = graph.query(authorizations) .has(VisalloProperties.CONCEPT_TYPE.getPropertyName(), PingOntology.IRI_CONCEPT_PING) .has(PingOntology.CREATE_DATE.getPropertyName(), Compare.GREATER_THAN, minutesAgo) .limit(0); q.addAggregation(new StatisticsAggregation(PingOntology.SEARCH_TIME_MS.getPropertyName(), PingOntology.SEARCH_TIME_MS.getPropertyName())); q.addAggregation(new StatisticsAggregation(PingOntology.RETRIEVAL_TIME_MS.getPropertyName(), PingOntology.RETRIEVAL_TIME_MS.getPropertyName())); q.addAggregation(new StatisticsAggregation(PingOntology.GRAPH_PROPERTY_WORKER_WAIT_TIME_MS.getPropertyName(), PingOntology.GRAPH_PROPERTY_WORKER_WAIT_TIME_MS.getPropertyName())); q.addAggregation(new StatisticsAggregation(PingOntology.LONG_RUNNING_PROCESS_WAIT_TIME_MS.getPropertyName(), PingOntology.LONG_RUNNING_PROCESS_WAIT_TIME_MS.getPropertyName())); QueryResultsIterable<Vertex> vertices = q.vertices(); StatisticsResult searchTimeAgg = vertices.getAggregationResult(PingOntology.SEARCH_TIME_MS.getPropertyName(), StatisticsResult.class); StatisticsResult retrievalTimeAgg = vertices.getAggregationResult(PingOntology.RETRIEVAL_TIME_MS.getPropertyName(), StatisticsResult.class); StatisticsResult gpwWaitTimeAgg = vertices.getAggregationResult(PingOntology.GRAPH_PROPERTY_WORKER_WAIT_TIME_MS.getPropertyName(), StatisticsResult.class); StatisticsResult lrpWaitTimeAgg = vertices.getAggregationResult(PingOntology.LONG_RUNNING_PROCESS_WAIT_TIME_MS.getPropertyName(), StatisticsResult.class); JSONObject json = new JSONObject(); json.put("pingCount", searchTimeAgg.getCount()); json.put("averageSearchTime", searchTimeAgg.getAverage()); json.put("averageRetrievalTime", retrievalTimeAgg.getAverage()); json.put("graphPropertyWorkerCount", gpwWaitTimeAgg.getCount()); json.put("averageGraphPropertyWorkerWaitTime", gpwWaitTimeAgg.getAverage()); json.put("longRunningProcessCount", lrpWaitTimeAgg.getCount()); json.put("averageLongRunningProcessWaitTime", lrpWaitTimeAgg.getAverage()); return json; }
@Test public void testVertexQueryWithNestedTermsAggregationOnExtendedData() { graph.defineProperty("name").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH, TextIndexHint.FULL_TEXT).define(); graph.defineProperty("gender").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define(); graph.prepareVertex("v1", VISIBILITY_EMPTY) .addExtendedData("t1", "r1", "name", "Joe", VISIBILITY_EMPTY) .addExtendedData("t1", "r1", "gender", "male", VISIBILITY_EMPTY) .addExtendedData("t1", "r2", "name", "Sam", VISIBILITY_EMPTY) .addExtendedData("t1", "r2", "gender", "male", VISIBILITY_EMPTY) .addExtendedData("t1", "r3", "name", "Sam", VISIBILITY_EMPTY) .addExtendedData("t1", "r3", "gender", "female", VISIBILITY_EMPTY) .addExtendedData("t1", "r4", "name", "Sam", VISIBILITY_EMPTY) .addExtendedData("t1", "r4", "gender", "female", VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B); Query q = v1.getExtendedData("t1").query(AUTHORIZATIONS_A_AND_B).limit(0); TermsAggregation agg = new TermsAggregation("terms-count", "name"); agg.addNestedAggregation(new TermsAggregation("nested", "gender")); assumeTrue("terms aggregation not supported", q.isAggregationSupported(agg)); q.addAggregation(agg); TermsResult aggregationResult = q.extendedDataRows().getAggregationResult("terms-count", TermsResult.class); Map<Object, Map<Object, Long>> vertexPropertyCountByValue = nestedTermsBucketToMap(aggregationResult.getBuckets(), "nested"); assertEquals(2, vertexPropertyCountByValue.size()); assertEquals(1, vertexPropertyCountByValue.get("Joe").size()); assertEquals(1L, (long) vertexPropertyCountByValue.get("Joe").get("male")); assertEquals(2, vertexPropertyCountByValue.get("Sam").size()); assertEquals(1L, (long) vertexPropertyCountByValue.get("Sam").get("male")); assertEquals(2L, (long) vertexPropertyCountByValue.get("Sam").get("female")); }
@Test public void testVertexQueryWithNestedTermsAggregationOnExtendedData() { graph.defineProperty("name").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH, TextIndexHint.FULL_TEXT).define(); graph.defineProperty("gender").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define(); graph.prepareVertex("v1", VISIBILITY_EMPTY) .addExtendedData("t1", "r1", "name", "Joe", VISIBILITY_EMPTY) .addExtendedData("t1", "r1", "gender", "male", VISIBILITY_EMPTY) .addExtendedData("t1", "r2", "name", "Sam", VISIBILITY_EMPTY) .addExtendedData("t1", "r2", "gender", "male", VISIBILITY_EMPTY) .addExtendedData("t1", "r3", "name", "Sam", VISIBILITY_EMPTY) .addExtendedData("t1", "r3", "gender", "female", VISIBILITY_EMPTY) .addExtendedData("t1", "r4", "name", "Sam", VISIBILITY_EMPTY) .addExtendedData("t1", "r4", "gender", "female", VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B); Query q = v1.getExtendedData("t1").query(AUTHORIZATIONS_A_AND_B).limit(0); TermsAggregation agg = new TermsAggregation("terms-count", "name"); agg.addNestedAggregation(new TermsAggregation("nested", "gender")); assumeTrue("terms aggregation not supported", q.isAggregationSupported(agg)); q.addAggregation(agg); TermsResult aggregationResult = q.extendedDataRows().getAggregationResult("terms-count", TermsResult.class); Map<Object, Map<Object, Long>> vertexPropertyCountByValue = nestedTermsBucketToMap(aggregationResult.getBuckets(), "nested"); assertEquals(2, vertexPropertyCountByValue.size()); assertEquals(1, vertexPropertyCountByValue.get("Joe").size()); assertEquals(1L, (long) vertexPropertyCountByValue.get("Joe").get("male")); assertEquals(2, vertexPropertyCountByValue.get("Sam").size()); assertEquals(1L, (long) vertexPropertyCountByValue.get("Sam").get("male")); assertEquals(2L, (long) vertexPropertyCountByValue.get("Sam").get("female")); }
.limit(0L); rows = q.extendedDataRows(); aggResult = termsBucketToMap(rows.getAggregationResult("agg", TermsResult.class).getBuckets()); .limit(0L); rows = q.extendedDataRows(); aggResult = termsBucketToMap(rows.getAggregationResult("agg", TermsResult.class).getBuckets()); .limit(0L); rows = q.extendedDataRows(); aggResult = termsBucketToMap(rows.getAggregationResult("agg", TermsResult.class).getBuckets());
.limit(0L); rows = q.extendedDataRows(); aggResult = termsBucketToMap(rows.getAggregationResult("agg", TermsResult.class).getBuckets()); .limit(0L); rows = q.extendedDataRows(); aggResult = termsBucketToMap(rows.getAggregationResult("agg", TermsResult.class).getBuckets()); .limit(0L); rows = q.extendedDataRows(); aggResult = termsBucketToMap(rows.getAggregationResult("agg", TermsResult.class).getBuckets());
@Override public QueryResultsIterableSearchResults run( SearchOptions searchOptions, User user, Authorizations authorizations ) { JSONArray filterJson = getFilterJson(searchOptions, searchOptions.getWorkspaceId()); QueryAndData queryAndData = getQuery(searchOptions, authorizations); applyFiltersToQuery(queryAndData, filterJson, user, searchOptions); applyConceptTypeFilterToQuery(queryAndData, searchOptions); applyEdgeLabelFilterToQuery(queryAndData, searchOptions); applySortToQuery(queryAndData, searchOptions); applyAggregationsToQuery(queryAndData, searchOptions); applyExtendedDataFilters(queryAndData, searchOptions); EnumSet<FetchHint> fetchHints = getFetchHints(searchOptions); Long size = searchOptions.getOptionalParameter("size", defaultSearchResultCount); if (size != null) { queryAndData.getQuery().limit(size); } Long offset = searchOptions.getOptionalParameter("offset", 0L); if (offset != null) { queryAndData.getQuery().skip(offset.intValue()); } QueryResultsIterable<? extends VertexiumObject> searchResults = getSearchResults(queryAndData, fetchHints); return new QueryResultsIterableSearchResults(searchResults, queryAndData, offset, size); }
.sort(Element.ID_PROPERTY_NAME, SortDirection.ASCENDING) .skip(0) .limit(1) .vertexIds(); assertIdsAnyOrder(idsIterable, "v1"); .sort(Element.ID_PROPERTY_NAME, SortDirection.ASCENDING) .skip(1) .limit(1) .vertexIds(); assertIdsAnyOrder(idsIterable, "v2"); .sort(Element.ID_PROPERTY_NAME, SortDirection.ASCENDING) .skip(2) .limit(1) .vertexIds(); assertIdsAnyOrder(idsIterable, "v3"); .sort(namePropertyName, SortDirection.ASCENDING) .skip(0) .limit(1) .vertices()); assertEquals(1, vertices.size());
.sort(Element.ID_PROPERTY_NAME, SortDirection.ASCENDING) .skip(0) .limit(1) .vertexIds(); assertIdsAnyOrder(idsIterable, "v1"); .sort(Element.ID_PROPERTY_NAME, SortDirection.ASCENDING) .skip(1) .limit(1) .vertexIds(); assertIdsAnyOrder(idsIterable, "v2"); .sort(Element.ID_PROPERTY_NAME, SortDirection.ASCENDING) .skip(2) .limit(1) .vertexIds(); assertIdsAnyOrder(idsIterable, "v3"); .sort(namePropertyName, SortDirection.ASCENDING) .skip(0) .limit(1) .vertices()); assertEquals(1, vertices.size());
.limit(size) .edges();
QueryResultsIterable<Vertex> results = graph.query(AUTHORIZATIONS_ALL) .addAggregation(agg) .limit(0) .vertices();
QueryResultsIterable<Vertex> results = graph.query(AUTHORIZATIONS_ALL) .addAggregation(agg) .limit(0) .vertices();
assertResultsCount(1, 3, idsIterable); idsIterable = graph.query(AUTHORIZATIONS_A).skip(1).limit(1).vertexIds(); assertResultsCount(1, 3, idsIterable); assertResultsCount(0, 3, idsIterable); idsIterable = graph.query(AUTHORIZATIONS_A).skip(2).limit(2).vertexIds(); assertResultsCount(1, 3, idsIterable);
assertResultsCount(1, 3, idsIterable); idsIterable = graph.query(AUTHORIZATIONS_A).skip(1).limit(1).vertexIds(); assertResultsCount(1, 3, idsIterable); assertResultsCount(0, 3, idsIterable); idsIterable = graph.query(AUTHORIZATIONS_A).skip(2).limit(2).vertexIds(); assertResultsCount(1, 3, idsIterable);