我正在尝试为图书馆系统构建推荐引擎。
这是我的数据库模式:
我的出发点是LoanerCard。然后,流程应如下所示:获取所有副本->获取物料->获取物料的所有副本(包括原始副本)->从副本获取LoanerCard->获取所有借出的副本->返回物料的名称副本+汇总数量以表明推荐的强度。
到目前为止,我最大的尝试是导致以下查询:
MATCH (L:LoanerCard {Barcode:"10007"})-[:LOANED]->(myLoans)-[:COPY_OF]-
(masterMaterial),
(masterMaterial)<-[:COPY_OF]-(allCopies),
(allCopies)<-[:LOANED]-(coLoaners),
(coLoaners)-[r:LOANED]->(theirCopies),
(theirCopies)-[:COPY_OF]-(materials)
RETURN materials.Title as Recommended, count(*) as Strength ORDER BY Strength DESC
这里的问题是,当我遍历图形时,它不包括原始副本和相邻的LoanerCard,因此从本质上讲,它仅遍历红色圆圈,而从未到达LoanerCard 10817, 10558
如何设计查询以使其包含这些?
答案 0 :(得分:1)
MATCH
子句自动过滤掉重复的关系。因此,为了遍历两次相同的关系,您需要将MATCH
子句一分为二。
尝试一下:
MATCH (:LoanerCard {Barcode:"10007"})-[:LOANED]->()-[:COPY_OF]-(masterMaterial)
MATCH (masterMaterial)<-[:COPY_OF]-()<-[:LOANED]-()-[:LOANED]->()-[:COPY_OF]-(materials)
RETURN materials.Title as Recommended, count(*) as Strength ORDER BY Strength DESC