【问题标题】:Slow neo4j Cypher Queries, using Baconator query for less-short paths than shortest path慢 Neo4j Cypher 查询,使用 Baconator 查询比最短路径更短的路径
【发布时间】:2014-08-12 18:34:10
【问题描述】:

我有一个带有 200,000 个节点和接近 400 万个关系(两种关系)的索引 neo4j 数据库。使用 C# API,我正在尝试执行“Baconator”类型的查询,它不仅为我提供了最短路径,还为我提供了其他一些较短的路径。 (例如,如果最短路径有 3 个节点,我也想看看长度为 4、5.. 等的其他亚军结果。

这是我首先使用的查询(在 C# 调用中):

string whereClause = "a.Id='" + userId.ToUpper() + "' and b.Id='" + targetId.ToUpper() + "'";

            var query = graphClient.Cypher
                .Match("p=allShortestPaths((a:Person)-[*..6]-(b:Person))")
                .Where(whereClause)
                .ReturnDistinct<List<Person>>("nodes(p)").Limit(5);

这只会给我最短长度的路径。为了获得其他较短的路径,我使用以下方法:

//nextDegree starts at the degree of the shortest path
while (nextDegree <= 6)
{
    var auxiliaryQuery = graphClient.Cypher
                    .Match("p=(a:Person)-[*" + (nextDegree) + ".." + (nextDegree) + "]-(b:Person)")
                    .Where(whereClause)
                    .ReturnDistinct<List<Person>>("nodes(p)").Limit(limit);
}

这可行,但性能会受到很大影响,因为查询在长度达到 5 时需要 30 多秒,而在达到 6 时需要几分钟。

我的问题是:有没有办法优化它? (通过使用 Cypher 中的简单路径算法或其他方法)

【问题讨论】:

    标签: c# neo4j cypher


    【解决方案1】:

    看看这个plugin to the GraphAware Framework,它是专门为这个用例编写的。它发现越来越长的最短路径。它尚未正式发布,但已准备好进行全面测试,您只需要自己构建它(如果需要帮助,请与我们联系)。

    构建后,只需将 jar 文件放入插件目录并调用 REST API。

    【讨论】:

    • 谢谢米哈尔!我会尝试尝试一下,看看这是否会缩短我的响应时间。
    猜你喜欢
    • 1970-01-01
    • 2013-04-04
    • 1970-01-01
    • 2022-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多