有没有一种方法可以获取SDN 4.0中节点的所有标签 [英] Is there a way to get all the labels for a node in SDN 4.0

查看:94
本文介绍了有没有一种方法可以获取SDN 4.0中节点的所有标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果要在SDN 4.0中的一个查询中做到这一点,我想获取所有标签都属于一个节点吗?

I want to get all the labels belongs to a node, if there a way to do this in one query in SDN 4.0?

例如,我当前的回购类似

For example, my current repo is like

Book findById(Long bookId);

@Query("MATCH (n:Book) where id(n)={0} set n:AnotherLabel return n")
Book updateBookLabel(Long bookId);

反正我可以简单地

book.getLabels();

检索该书节点的所有标签.

to retrieve all the labels for this book node.

这本书的课是

@NodeEntity
public class Book extends Something {
}

是的,默认情况下,我的Book节点应该有两个标签BookSomething.由于我在仓库中有一个更新方法来添加另一个标签.无论如何,我可以检索带有所有3个标签的书吗?

Yes, by default, my Book node should has two label Book and Something.Since I have a update method in the repo to add another label. Anyway I can retrieve the book with all 3 labels?

谢谢

推荐答案

做到这一点的唯一方法是通过自定义查询-

The only way to do this is via a custom query -

@Query("MATCH (n:Book) where id(n)={0} return labels(n) as labels")
List<String> getBookLabels(Long bookId);

(未经测试)

根据评论进行更新

Update based on comment

要在单个查询中返回标签和节点属性,请使用@QueryResult-

To return labels and the node properties in a single query, use a @QueryResult-

SDN 4.0 (无法将节点和关系从自定义查询映射到查询结果中的域实体):

SDN 4.0 (cannot map nodes and relationships from a custom query to domain entities in a query result):

@QueryResult
public class BookResult {
    Long id;
    Map<String,Object> node;
    List<String> labels;
 }

@Query("MATCH (n:Book) where id(n)={0} return labels(n) as labels, ID(n) as id, {properties: n} as node")
BookResult getBookLabels(Long bookId);

SDN 4.1

 @QueryResult
 public class BookResult {
      Book node;
      List<String> labels;
 }

 @Query("MATCH (n:Book) where id(n)={0} return labels(n) as labels, n as node")
 BookResult getBookLabels(Long bookId);

这篇关于有没有一种方法可以获取SDN 4.0中节点的所有标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆