use of com.baidu.hugegraph.traversal.algorithm.CustomizePathsTraverser in project incubator-hugegraph by apache.
the class CustomizedPathsAPI method post.
@POST
@Timed
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String post(@Context GraphManager manager, @PathParam("graph") String graph, PathRequest request) {
E.checkArgumentNotNull(request, "The path request body can't be null");
E.checkArgumentNotNull(request.sources, "The sources of path request can't be null");
E.checkArgument(request.steps != null && !request.steps.isEmpty(), "The steps of path request can't be empty");
if (request.sortBy == null) {
request.sortBy = SortBy.NONE;
}
LOG.debug("Graph [{}] get customized paths from source vertex '{}', " + "with steps '{}', sort by '{}', capacity '{}', limit '{}' " + "and with_vertex '{}'", graph, request.sources, request.steps, request.sortBy, request.capacity, request.limit, request.withVertex);
HugeGraph g = graph(manager, graph);
Iterator<Vertex> sources = request.sources.vertices(g);
List<WeightedEdgeStep> steps = step(g, request);
boolean sorted = request.sortBy != SortBy.NONE;
CustomizePathsTraverser traverser = new CustomizePathsTraverser(g);
List<HugeTraverser.Path> paths;
paths = traverser.customizedPaths(sources, steps, sorted, request.capacity, request.limit);
if (sorted) {
boolean incr = request.sortBy == SortBy.INCR;
paths = CustomizePathsTraverser.topNPath(paths, incr, request.limit);
}
if (!request.withVertex) {
return manager.serializer(g).writePaths("paths", paths, false);
}
Set<Id> ids = new HashSet<>();
for (HugeTraverser.Path p : paths) {
ids.addAll(p.vertices());
}
Iterator<Vertex> iter = QueryResults.emptyIterator();
if (!ids.isEmpty()) {
iter = g.vertices(ids.toArray());
}
return manager.serializer(g).writePaths("paths", paths, false, iter);
}
Aggregations