Java neo4j ogm,获取与特定查询匹配的节点数

Java neo4j ogm,获取与特定查询匹配的节点数,java,neo4j,spring-data-neo4j,neo4j-ogm,Java,Neo4j,Spring Data Neo4j,Neo4j Ogm,我的graphDb中有3种类型的节点技能,SkillSubCluster&SkillCluster。Skill节点连接到一个或多个SkillSubCluster节点(1对多关系),而SkillSubCluster节点连接到单个SkillCluster节点(1对1关系) 我想找到skillCluster名称中给出的所有技能。我提出了这个密码问题- match(n:SkillCluster {CleanedText: "arts"}) match(n)<-[parent]-(x)<-[b

我的graphDb中有3种类型的节点<代码>技能,
SkillSubCluster
&
SkillCluster
Skill
节点连接到一个或多个
SkillSubCluster
节点(1对多关系),而
SkillSubCluster
节点连接到单个
SkillCluster
节点(1对1关系)

我想找到
skillCluster
名称中给出的所有技能。我提出了这个密码问题-

match(n:SkillCluster {CleanedText: "arts"}) match(n)<-[parent]-(x)<-[belongsTo]-(y) return y
我正试图使用neo4j ogm for java实现同样的功能

我的技能课是

public class Skill {
    @Id @GeneratedValue
    private Long id;
    private String Name;
    private String CleanedText;

    @Relationship(type = "BelongsTo", direction = Relationship.OUTGOING)
    private Set<SkillSubCluster> belongsTo = new HashSet<>();
}
公开课技能{
@Id@GeneratedValue
私人长id;
私有字符串名称;
私有字符串清理文本;
@关系(type=“BelongsTo”,direction=Relationship.OUTGOING)
private Set belongsTo=new HashSet();
}
它对应的DAO类

public class SkillDAO extends GenericDAO<Skill>{
    public SkillDAO(Session session) {
        super(session);
    }

    protected Class<Skill> getEntityType() {
        return Skill.class;
    }   
}
公共类SkillDAO扩展了GenericDAO{
公共技能DAO(课程){
超级(会议);
}
受保护类getEntityType(){
返回技能等级;
}   
}
还有我的泛型DAO类-

public abstract class GenericDAO<T> {
    private static final int DEPTH_LIST = 0;
    private static final int DEPTH_ENTITY = 1;  
    private Session session;

    public long filterCount(Iterable<Filter> filters){
        return session.count(getEntityType(), filters);
    }

    public T find(Long id) {
        return session.load(getEntityType(), id, DEPTH_ENTITY);
    }

    public T find(String name) {
        return session.load(getEntityType(), name, DEPTH_ENTITY);
    }

    public void delete(Long id) {
        session.delete(session.load(getEntityType(), id));
    }

    public void createOrUpdate(T entity) {
        session.save(entity, DEPTH_ENTITY);
        //return find(entity.id);
    }

    protected abstract Class<T> getEntityType();

    public GenericDAO(Session session) {
        this.session = session;
    }
}      
公共抽象类GenericDAO{
私有静态最终整数深度列表=0;
私有静态最终整数深度_实体=1;
非公开会议;
公共长筛选器计数(可替换筛选器){
返回session.count(getEntityType(),过滤器);
}
公共找不到(长id){
返回session.load(getEntityType(),id,DEPTH\u ENTITY);
}
公共查找(字符串名称){
返回session.load(getEntityType(),name,DEPTH\u ENTITY);
}
公共无效删除(长id){
delete(session.load(getEntityType(),id));
}
公共无效createOrUpdate(T实体){
session.save(实体、深度实体);
//返回find(entity.id);
}
受保护的抽象类getEntityType();
公共通用DAO(会话){
this.session=会话;
}
}      

除了
Skill
类之外,是否有可能返回其他对象,或者获得复杂的
cypher
查询的结果,如
groupby
等。

经过一段时间的挖掘,我找到了正确的方法。因此,在我的GenericDAO抽象类中,我必须添加以下方法-

public abstract class GenericDAO<T> {
    // Rest of the implementation from above 

    public Result runComplexQuery(String query){
        return session.query(query, Collections.emptyMap());    
    }

    // ..................
}
公共抽象类GenericDAO{
//其余的实现来自上面
公共结果runComplexQuery(字符串查询){
返回session.query(query,Collections.emptyMap());
}
// ..................
}
然后使用以下代码获取计数-

public long getNodeCount(String clusterName){
    query = "match(n:SkillCluster {CleanedText: \"" + clusterName.toLowerCase() + "\"}) " 
    + "match(n)<-[parent]-(x)<-[belongsTo]-(y) return count(y) as numSkillNodes";

    Iterable<Map<String, Object>> results = skillSubClusterDAO.runComplexQuery(query);

    for(Map<String, Object> row: results){
        count = (long) row.get("numSkillNodes");
        System.out.println(count);
    }
}
public长getNodeCount(字符串clusterName){
query=“匹配(n:SkillCluster{CleanedText:\”“+clusterName.toLowerCase()+”\“})”
+“匹配(n)
public long getNodeCount(String clusterName){
    query = "match(n:SkillCluster {CleanedText: \"" + clusterName.toLowerCase() + "\"}) " 
    + "match(n)<-[parent]-(x)<-[belongsTo]-(y) return count(y) as numSkillNodes";

    Iterable<Map<String, Object>> results = skillSubClusterDAO.runComplexQuery(query);

    for(Map<String, Object> row: results){
        count = (long) row.get("numSkillNodes");
        System.out.println(count);
    }
}