0
我想要可視化neo4j的數據,我需要返回某個子圖的所有節點和邊。 (:User) - [:RATED] - >(:Movie) - [:HAS_GENRE] - >(:Genre),(:User) - [:SIMILAIRITY] - >( :用戶)。我想要顯示中心是指定電影的子圖。如何使用密碼返回neo4j中多節點或邊的集合
該代碼的相關部分如下所示。
@Query("match (u:User)-[r:RATED]->(m:Movie)-[hg:HAS_GENRE]->(g:Genre) where m.id={0} return id(u) as id, case labels(u)[0] when 'Genre' then u.name when 'User' then u.id when 'Movie' then u.title end as caption, labels(u)[0] as type "
+ "union "
+ "match (u:User)-[r:RATED]->(m:Movie)-[hg:HAS_GENRE]->(g:Genre) where m.id={0} return id(m) as id, case labels(m)[0] when 'Genre' then m.name when 'User' then m.id when 'Movie' then m.title end as caption, labels(m)[0] as type "
+ "union "
+ "match (u:User)-[r:RATED]->(m:Movie)-[hg:HAS_GENRE]->(g:Genre) where m.id={0} return id(g) as id, case labels(g)[0] when 'Genre' then g.name when 'User' then g.id when 'Movie' then g.title end as caption, labels(g)[0] as type")
List<NodeInfo> findMovieRelevantNodes(int movieId);
@Query("match (u:User)-[r:RATED]->(m:Movie)-[hg:HAS_GENRE]->(g:Genre) where m.id={0} return id(u) as source,type(r) as type, id(m) as target, case type(r) when 'HAS_GENRE' then r.probability when 'SIMILARITY' then r.similarity when 'RATED' then r.rate end as caption "
+ "union "
+ "match (u:User)-[r:RATED]->(m:Movie)-[hg:HAS_GENRE]->(g:Genre) where m.id={0} return id(m) as source,type(hg) as type, id(g) as target, case type(hg) when 'HAS_GENRE' then r.probability when 'SIMILARITY' then r.similarity when 'RATED' then r.rate end as caption")
List<EdgeInfo> findMovieRelevantEdges(int movieId);
@QueryResult
public interface NodeInfo {
@ResultColumn("id")
int getId();
@ResultColumn("caption")
String getCaption();
@ResultColumn("type")
String getType();
}
@QueryResult
public interface EdgeInfo {
@ResultColumn("source")
int getSource();
@ResultColumn("type")
String getType();
@ResultColumn("target")
int getTarget();
@ResultColumn("caption")
String getCaption();
}
它看起來像冗餘和性能差。那麼是否有更好的方法來重寫這些密碼查詢。
無法運作。它返回像這樣的地圖列表「{genre = {id = 5,caption = Comedy,type = Genre},movie = {id = 22,caption = Toy Story(1995),type = Movie},user = {id = 19,caption = 1,type = User}}「 –