我已尝试多次实现此功能,但目前尚无法实现,因此在Stack Overflow中发布
在我目前的应用程序中,我们需要找到一起出现的不同3个引号的#次。背景是这样的 一篇文章可以包含多个引号,并且相同的引用可以出现在多个文章中,我需要找出所有那些需求最高的引号(试图在一对中),尝试在Cypher中执行此操作但看起来非常复杂。 ..
插入查询如下
CREATE (ART449211:Article {id: '449211', pages:20, author: 'MAT LONG' })
CREATE (ART559233:Article {id: '559233', pages:78, author: 'ANDREW KING' })
CREATE (ART765432:Article {id: '765432', pages:65, author: 'STEPHEN JOHN' })
CREATE (ART112244:Article {id: '112244', pages:30, author: 'REV PHILIP' })
CREATE (ART908789:Article {id: '908789', pages:40, author: 'JOE MUSK' })
CREATE (ART123321:Article {id: '123321', pages:63, author: 'KING KONG' })
CREATE (ART887651:Article {id: '887651', pages:18, author: 'LILY MATHEW' })
CREATE (ART800704:Article {id: '800704', pages:24, author: 'GEORGE L' })
CREATE (ART600333:Article {id: '600333', pages:10, author: 'SHIRIN JOHN' })
CREATE (QUOTE123456:Quote {num: '123456', name : 'QUOTE A', desc: 'QUOTE A-TEXT' })
CREATE (QUOTE765980:Quote {num: '765980', name : 'QUOTE B', desc: 'QUOTE B-TEXT' })
CREATE (QUOTE987681:Quote {num: '987681', name : 'QUOTE C', desc: 'QUOTE C-TEXT' })
CREATE (QUOTE876982:Quote {num: '876982', name : 'QUOTE D', desc: 'QUOTE D-TEXT' })
CREATE (QUOTE776983:Quote {num: '776983', name : 'QUOTE E', desc: 'QUOTE E-TEXT' })
CREATE (QUOTE765984:Quote {num: '765984', name : 'QUOTE F', desc: 'QUOTE F-TEXT' })
CREATE (QUOTE436724:Quote {num: '436724', name : 'QUOTE G', desc: 'QUOTE G-TEXT' })
CREATE (QUOTE362984:Quote {num: '362984', name : 'QUOTE H', desc: 'QUOTE H-TEXT' })
CREATE (QUOTE764444:Quote {num: '764444', name : 'QUOTE I', desc: 'QUOTE I-TEXT' })
CREATE (QUOTE888984:Quote {num: '888984', name : 'QUOTE J', desc: 'QUOTE J-TEXT' })
CREATE (QUOTE654009:Quote {num: '654009', name : 'QUOTE K', desc: 'QUOTE K-TEXT' })
CREATE (QUOTE431110:Quote {num: '431110', name : 'QUOTE L', desc: 'QUOTE L-TEXT' })
CREATE (QUOTE565678:Quote {num: '565678', name : 'QUOTE M', desc: 'QUOTE M-TEXT' })
CREATE (QUOTE009876:Quote {num: '009876', name : 'QUOTE N', desc: 'QUOTE N-TEXT' })
CREATE (QUOTE543222:Quote {num: '543222', name : 'QUOTE O', desc: 'QUOTE O-TEXT' })
CREATE
(ART449211)-[:CONTAINS]->(QUOTE123456),
(ART449211)-[:CONTAINS]->(QUOTE765980),
(ART449211)-[:CONTAINS]->(QUOTE987681),
(ART449211)-[:CONTAINS]->(QUOTE876982),
(ART449211)-[:CONTAINS]->(QUOTE654009),
(ART559233)-[:CONTAINS]->(QUOTE123456),
(ART559233)-[:CONTAINS]->(QUOTE765980),
(ART559233)-[:CONTAINS]->(QUOTE987681),
(ART559233)-[:CONTAINS]->(QUOTE876982),
(ART559233)-[:CONTAINS]->(QUOTE431110),
(ART765432)-[:CONTAINS]->(QUOTE123456),
(ART765432)-[:CONTAINS]->(QUOTE765980),
(ART765432)-[:CONTAINS]->(QUOTE987681),
(ART765432)-[:CONTAINS]->(QUOTE876982),
(ART765432)-[:CONTAINS]->(QUOTE565678),
(ART112244)-[:CONTAINS]->(QUOTE123456),
(ART112244)-[:CONTAINS]->(QUOTE765980),
(ART112244)-[:CONTAINS]->(QUOTE987681),
(ART112244)-[:CONTAINS]->(QUOTE876982),
(ART112244)-[:CONTAINS]->(QUOTE009876),
(ART908789)-[:CONTAINS]->(QUOTE987681),
(ART908789)-[:CONTAINS]->(QUOTE876982),
(ART908789)-[:CONTAINS]->(QUOTE888984),
(ART123321)-[:CONTAINS]->(QUOTE987681),
(ART123321)-[:CONTAINS]->(QUOTE876982),
(ART123321)-[:CONTAINS]->(QUOTE888984),
(ART887651)-[:CONTAINS]->(QUOTE987681),
(ART887651)-[:CONTAINS]->(QUOTE876982),
(ART887651)-[:CONTAINS]->(QUOTE888984),
(ART800704)-[:CONTAINS]->(QUOTE765984),
(ART800704)-[:CONTAINS]->(QUOTE436724),
(ART800704)-[:CONTAINS]->(QUOTE362984),
(ART600333)-[:CONTAINS]->(QUOTE765984),
(ART600333)-[:CONTAINS]->(QUOTE436724),
(ART600333)-[:CONTAINS]->(QUOTE362984);
Quote 123456, 765980, 987681 - present in 4 Articles
Quote 123456, 765980, 876982 - present in 4 Articles
Quote 765980, 987681, 876982 - present in 4 Articles
Quote 987681, 876982, 888984 - present in 3 Articles
Quote 765984, 436724, 362984 - present in 2 Articles
基本上 - 需要提取所有3个引号的集合,然后找出它们一起出现的文章数量,并在desc计数中对它们进行排序。
输入请...
由于
答案 0 :(得分:0)
我认为这就是你要找的东西:
MATCH (a:Article)-[:CONTAINS]->(q1:Quote),
(a:Article)-[:CONTAINS]->(q2:Quote),
(a:Article)-[:CONTAINS]->(q3:Quote)
WHERE id(q1) < id(q2) AND id(q2) < id(q3) // avoid dups in different orders
RETURN q1.num, q2.num, q3.num, count(a) AS present_in
ORDER BY present_in DESC