【问题标题】:Neo4j Query returns multiple records after first timeNeo4j Query 第一次后返回多条记录
【发布时间】:2017-05-16 08:48:23
【问题描述】:

我正在使用带有 ASP.NET MVC 的 Neo4j 客户端,我有这个查询,它显示了一个日期范围内的用户事件,当我第一次运行这个查询时,它会正确返回事件但是当我调用我的 ajax再次运行事件查询给我的记录是第一次的两倍。我已经逐行跟踪查询,但一切似乎都运行良好,我不得不说我第一次使用Union 可以查看我的查询并告诉我是否有问题?

var q = new CypherFluentQuery(client) as ICypherFluentQuery;
q = q.Match("(y:Year)--(m:Month)--(d:Day)--(h:Hour)--(sr:ServiceRequest)-[" + Relations.EXPERT_ASSIGN_TO_SQ.ToString() + "]-(u:User)")
     .Where("y.value >= {param}").WithParam("param", dt1.Year)
     .AndWhere("m.value >= {param2}").WithParam("param2", dt1.Month)
     .AndWhere("d.value >= {param4}").WithParam("param4", dt1.Day)
     .AndWhere("u.Id = {param10}").WithParam("param10", Id)
     .With("y,m,d,h,sr,u")
     .Match("(sr)-[:" + Relations.SC_HAS_SQ.ToString() + "]-(c2:ServiceCategory)-[:" + Relations.SC_IS_SC_CHILD.ToString() + "*]-(c3:ServiceCategory)")
     .ReturnDistinct((y, m, d, h, sr, c2, c3) => new
     {
         Year = y.As<RootTree>().value,
         Month = m.As<RootTree>().value,
         Day = d.As<RootTree>().value,
         Hour = h.As<RootTree>().value,
         serviceRequest = sr.As<ServiceRequest>(),
         ServiceCategory = c2.As<OnDemandService>(),
         ServiceParent = c3.As<OnDemandService>()

     })
     .UnionAll()
     .Match("(yy:Year)--(mm:Month)--(dd:Day)--(hh:Hour)--(sr2:ServiceRequest)-[" + Relations.EXPERT_ASSIGN_TO_SQ.ToString() + "]-(u)")
     .Where("yy.value <= {param7}").WithParam("param7", dt2.Year)
     .AndWhere("mm.value >= {param8}").WithParam("param8", dt2.Month)
     .AndWhere("dd.value >= {param9}").WithParam("param9", dt2.Day)
     .With("yy,mm,dd,hh,sr2,u")
     .Match("(sr2)-[:" + Relations.SC_HAS_SQ.ToString() + "]-(c2:ServiceCategory)-[:" + Relations.SC_IS_SC_CHILD.ToString() + "*]-(c3:ServiceCategory)");

var query = q.ReturnDistinct((yy, mm, dd, hh, sr2, c2, c3) => new
{
    Year = yy.As<RootTree>().value,
    Month = mm.As<RootTree>().value,
    Day = dd.As<RootTree>().value,
    Hour = hh.As<RootTree>().value,
    serviceRequest = sr2.As<ServiceRequest>(),
    ServiceCategory = c2.As<OnDemandService>(),
    ServiceParent = c3.As<OnDemandService>()
}).Results.ToList();

跟踪的查询:

MATCH (y:Year)--(m:Month)--(d:Day)--(h:Hour)--(sr:ServiceRequest)-[EXPERT_ASSIGN_TO_SQ]-(u:User)
WHERE y.value >= 2017
AND m.value >= 5
AND d.value >= 16
AND u.Id = "c0dc7cbe-5626-4012-a5ea-72c1cfce2461"
WITH y,m,d,h,sr,u
MATCH (sr)-[:SC_HAS_SQ]-(c2:ServiceCategory)-[:SC_IS_SC_CHILD*]-(c3:ServiceCategory)
RETURN distinct y.value AS Year, m.value AS Month, d.value AS Day, h.value AS Hour, sr AS serviceRequest, c2 AS ServiceCategory, c3 AS ServiceParent
UNION ALL
MATCH (yy:Year)--(mm:Month)--(dd:Day)--(hh:Hour)--(sr2:ServiceRequest)-[EXPERT_ASSIGN_TO_SQ]-(u)
WHERE yy.value <= 2017
AND mm.value >= 5
AND dd.value >= 9
WITH yy,mm,dd,hh,sr2,u
MATCH (sr2)-[:SC_HAS_SQ]-(c2:ServiceCategory)-[:SC_IS_SC_CHILD*]-(c3:ServiceCategory)
RETURN distinct yy.value AS Year, mm.value AS Month, dd.value AS Day, hh.value AS Hour, sr2 AS serviceRequest, c2 AS ServiceCategory, c3 AS ServiceParent

更新

我已经在 neo4j 本身上运行了多次它正确返回的查询,只有当查询在我的应用程序中使用 neo4jClient 运行时才会发生这种情况

【问题讨论】:

  • 如果您在控制台应用程序中连续调用该代码两次,第二次是否也返回多个条目?
  • @ChrisSkardon 是的.. 第一次正确返回,但第二次返回每个记录的重复记录,即使我返回不同的记录
  • @ChrisSkardon 我发现了这个问题,这是因为UNION ALL 我把它改成了union 并且工作了。

标签: neo4j cypher neo4jclient


【解决方案1】:

实际上它很简单,因为我使用了union all,我将其更改为union,它起作用了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多