use of org.unipop.query.predicates.PredicatesHolder in project unipop by unipop-graph.
the class UniVertex method edges.
@Override
public Iterator<Edge> edges(Direction direction, String... edgeLabels) {
PredicatesHolder predicatesHolder = (edgeLabels.length == 0) ? PredicatesHolderFactory.empty() : PredicatesHolderFactory.predicate(new HasContainer(T.label.getAccessor(), P.within(edgeLabels)));
SearchVertexQuery searchVertexQuery = new SearchVertexQuery(Edge.class, Arrays.asList(this), direction, predicatesHolder, -1, null, null, null, null);
return graph.getControllerManager().getControllers(SearchVertexQuery.SearchVertexController.class).stream().<Iterator<Edge>>map(controller -> controller.search(searchVertexQuery)).flatMap(ConversionUtils::asStream).iterator();
}
use of org.unipop.query.predicates.PredicatesHolder in project unipop by unipop-graph.
the class VirtualController method search.
@Override
public <E extends Element> Iterator<E> search(SearchQuery<E> uniQuery) {
if (uniQuery.getReturnType() != Vertex.class)
return EmptyIterator.instance();
PredicatesHolder predicates = uniQuery.getPredicates();
List<? extends VirtualVertexSchema> filteredSchemas = vertexSchemas.stream().filter(schema -> !schema.toPredicates(predicates).getClause().equals(PredicatesHolder.Clause.Abort)).collect(Collectors.toList());
Optional<HasContainer> ids = predicates.getPredicates().stream().filter(has -> has.getKey().equals(T.id.getAccessor())).findFirst();
Optional<HasContainer> labels = predicates.getPredicates().stream().filter(has -> has.getKey().equals(T.label.getAccessor())).findFirst();
if (!ids.isPresent() || !labels.isPresent()) {
return EmptyIterator.instance();
}
ArrayList<Map<String, Object>> elements = new ArrayList<>();
Object idObject = ids.get().getValue();
Collection<Object> idsCol = idObject instanceof Collection ? ((Collection) idObject) : Collections.singleton(idObject);
Object labelObject = labels.get().getValue();
Collection<Object> labelCol = labelObject instanceof Collection ? ((Collection) labelObject) : Collections.singleton(labelObject);
idsCol.forEach(id -> labelCol.forEach(label -> elements.add(createElement(id, label.toString()))));
return (Iterator<E>) elements.stream().flatMap(fields -> filteredSchemas.stream().flatMap(schema -> Stream.of(schema.createElement(fields)))).filter(v -> v != null).iterator();
}
use of org.unipop.query.predicates.PredicatesHolder in project unipop by unipop-graph.
the class NestedEdgeSchema method getSearch.
@Override
public QueryBuilder getSearch(SearchQuery<Edge> query) {
PredicatesHolder predicatesHolder = this.toPredicates(query.getPredicates());
QueryBuilder queryBuilder = createQueryBuilder(predicatesHolder);
if (queryBuilder == null)
return null;
return QueryBuilders.nestedQuery(this.path, queryBuilder, ScoreMode.None);
}
Aggregations