Search in sources :

Example 1 with Property

use of org.neo4j.cypherdsl.core.Property in project openk9 by smclab.

the class CreateEntitiesRunnable method _getEntityGraphs.

private List<EntityGraph> _getEntityGraphs(EntityGraphService entityGraphService, List<EntityIndex> entityRequestList, int minHops, int maxHops, String currentEntityRequestType, List<EntityGraph> result) {
    if (_log.isDebugEnabled()) {
        _log.debug("disambiguating with search entity with type " + currentEntityRequestType);
    }
    Statement[] statements = new Statement[entityRequestList.size()];
    for (int i = 0; i < entityRequestList.size(); i++) {
        EntityIndex entityRequest = entityRequestList.get(i);
        Node nodeEntity = Cypher.node(entityRequest.getType()).named("entity");
        AliasedExpression entityAliased = nodeEntity.as("entity");
        SymbolicName path = Cypher.name("path");
        Property idProperty = entityAliased.getDelegate().property("id");
        Statement statement = Cypher.match(nodeEntity).where(idProperty.eq(literalOf(entityRequest.getId()))).call("apoc.path.expand").withArgs(entityAliased.getDelegate(), literalOf(null), literalOf("-date"), literalOf(minHops), literalOf(maxHops)).yield(path).returning(Functions.last(Functions.nodes(path)).as("node"), Functions.size(Functions.nodes(path)).subtract(literalOf(1)).as("hops")).build();
        statements[i] = statement;
    }
    if (statements.length == 1) {
        Statement entityRequestListStatement = Cypher.call(statements[0]).returning("node", "hops").orderBy(Cypher.name("hops")).build();
        result = entityGraphService.search(entityRequestListStatement);
    } else if (statements.length > 1) {
        Statement entityRequestListStatement = Cypher.call(Cypher.unionAll(statements)).returning("node", "hops").orderBy(Cypher.name("hops")).build();
        result = entityGraphService.search(entityRequestListStatement);
    }
    return result;
}
Also used : Statement(org.neo4j.cypherdsl.core.Statement) Node(org.neo4j.cypherdsl.core.Node) EntityIndex(io.openk9.entity.manager.model.index.EntityIndex) SymbolicName(org.neo4j.cypherdsl.core.SymbolicName) Property(org.neo4j.cypherdsl.core.Property) AliasedExpression(org.neo4j.cypherdsl.core.AliasedExpression)

Example 2 with Property

use of org.neo4j.cypherdsl.core.Property in project openk9 by smclab.

the class EntityGraphRepositoryImpl method getEntities.

@Override
public Flux<Entity> getEntities(long tenantId, String entityType) {
    Node entity = Cypher.node(entityType).named(Constants.ENTITY);
    Property tenantIdProperty = entity.property(Constants.ENTITY_TENANT_ID_FIELD);
    Statement statement = Cypher.match(entity).where(tenantIdProperty.eq(literalOf(tenantId))).returning(entity).build();
    return Flux.from(getEntities(statement));
}
Also used : Statement(org.neo4j.cypherdsl.core.Statement) Node(org.neo4j.cypherdsl.core.Node) Property(org.neo4j.cypherdsl.core.Property)

Aggregations

Node (org.neo4j.cypherdsl.core.Node)2 Property (org.neo4j.cypherdsl.core.Property)2 Statement (org.neo4j.cypherdsl.core.Statement)2 EntityIndex (io.openk9.entity.manager.model.index.EntityIndex)1 AliasedExpression (org.neo4j.cypherdsl.core.AliasedExpression)1 SymbolicName (org.neo4j.cypherdsl.core.SymbolicName)1