多个链表中的节点

时间:2016-05-25 09:24:00

标签: database-design graph neo4j

在我们的NEO4j图表中,我们为指定的类别创建了顶级项目的serval链表。

示例:

2016-01前50周 - 迈克波斯纳 - 非洲劫持者 - 威利威廉

此时我们创建了这个:

const gulp = require('gulp');
const zip = require('gulp-zip');

gulp.task('default', () => {
    return gulp.src('css/*')
        .pipe(zip('resources.zip'))
        .pipe(gulp.dest('build'));
});

但是现在下周,订单改为Willy,Mike,Afro。现在我们最终会在每个艺术家身上建立多个下一个关系。遍历列表将会明显变慢。

任何想法,我们如何以更好的方式对此进行建模。

2 个答案:

答案 0 :(得分:2)

来自@ stdob--的答案非常有效,但这不能很好地扩展。

想象一下,你想要找到所有曾经是1号和多少次的艺术家,你必须匹配所有这些艺术家,以及遍历所有关系并过滤排名属性。如果你有100万艺术家,这将是一场噩梦。

LinkedList的想法很好,但LinkedList中的节点可以是例如与艺术家相关的RankItem节点。

(week1)-[:FIRST]->(rankItem)<-[:HAS_RANKING_POSITON]-(artist)

对于上一个问题,您可以这样做:

MATCH (w:Week)-[:FIRST]->()<-[:HAS_RANKING_POSITION]-(artist)
RETURN artist, count(*) as occurences

根据您需要执行的查询,有时候还有一个RankItem也将连接的RankingList。

(ranking {v:1})-[:NEXT]->(ranking {v:2})-[:NEXT]->(.....

在这种情况下,RankingItem也将连接到列表

使问题更具性能,例如:

  

基于艺术家,找到我有共同模式的艺术家   排名历史

答案 1 :(得分:0)

我想你会接近这个模型:

(T1:Top {name:'Top week1'})-[:include {rank:0}]->(P1:Person {name: 'mike posner'})
(T1:Top {name:'Top week1'})-[:include {rank:1}]->(P1:Person {name: 'afrojack'})
(T1:Top {name:'Top week1'})-[:include {rank:2}]->(P1:Person {name: 'willy'})

(T2:Top {name:'Top week2'})-[:include {rank:1}]->(P1:Person {name: 'mike posner'})
(T2:Top {name:'Top week2'})-[:include {rank:0}]->(P1:Person {name: 'afrojack'})
(T2:Top {name:'Top week2'})-[:include {rank:2}]->(P1:Person {name: 'willy'})

(T3:Top {name:'Top week3'})-[:include {rank:2}]->(P1:Person {name: 'mike posner'})
(T3:Top {name:'Top week3'})-[:include {rank:1}]->(P1:Person {name: 'afrojack'})
(T3:Top {name:'Top week3'})-[:include {rank:0}]->(P1:Person {name: 'willy'})

enter image description here

并查询以获得特定周的顶部:

MATCH (T:Top {name:'TOP week1'})-[r:include]->(P:Person) 
RETURN P.name, r.rank ORDER BY r.rank