Search in sources :

Example 21 with PredicatesHolder

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();
}
Also used : PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) SearchVertexQuery(org.unipop.query.search.SearchVertexQuery)

Example 22 with PredicatesHolder

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();
}
Also used : java.util(java.util) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) AddVertexQuery(org.unipop.query.mutation.AddVertexQuery) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SimpleController(org.unipop.query.controller.SimpleController) T(org.apache.tinkerpop.gremlin.structure.T) Maps(com.google.common.collect.Maps) EmptyIterator(org.apache.tinkerpop.gremlin.util.iterator.EmptyIterator) Collectors(java.util.stream.Collectors) AddEdgeQuery(org.unipop.query.mutation.AddEdgeQuery) Element(org.apache.tinkerpop.gremlin.structure.Element) Stream(java.util.stream.Stream) RemoveQuery(org.unipop.query.mutation.RemoveQuery) NotImplementedException(org.apache.commons.lang.NotImplementedException) ElementSchema(org.unipop.schema.element.ElementSchema) UniGraph(org.unipop.structure.UniGraph) PropertyQuery(org.unipop.query.mutation.PropertyQuery) UniEdge(org.unipop.structure.UniEdge) PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) DeferredVertexQuery(org.unipop.query.search.DeferredVertexQuery) SearchQuery(org.unipop.query.search.SearchQuery) Edge(org.apache.tinkerpop.gremlin.structure.Edge) SearchVertexQuery(org.unipop.query.search.SearchVertexQuery) UniVertex(org.unipop.structure.UniVertex) PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) EmptyIterator(org.apache.tinkerpop.gremlin.util.iterator.EmptyIterator)

Example 23 with PredicatesHolder

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);
}
Also used : PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) NestedQueryBuilder(org.elasticsearch.index.query.NestedQueryBuilder)

Aggregations

PredicatesHolder (org.unipop.query.predicates.PredicatesHolder)23 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)9 Collectors (java.util.stream.Collectors)7 java.util (java.util)6 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)6 Stream (java.util.stream.Stream)5 P (org.apache.tinkerpop.gremlin.process.traversal.P)5 JSONObject (org.json.JSONObject)5 PredicatesHolderFactory (org.unipop.query.predicates.PredicatesHolderFactory)4 SearchQuery (org.unipop.query.search.SearchQuery)4 AddVertexQuery (org.unipop.query.mutation.AddVertexQuery)3 ConversionUtils (org.unipop.util.ConversionUtils)3 Configuration (org.apache.commons.configuration.Configuration)2 StringUtils (org.apache.commons.lang3.StringUtils)2 GraphComputer (org.apache.tinkerpop.gremlin.process.computer.GraphComputer)2 TraversalStrategies (org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies)2 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)2 org.apache.tinkerpop.gremlin.structure (org.apache.tinkerpop.gremlin.structure)2 Element (org.apache.tinkerpop.gremlin.structure.Element)2 JSONArray (org.json.JSONArray)2