Neo4j Query第一次返回多条记录

时间:2017-05-16 08:48:24

标签: neo4j cypher neo4jclient

我正在使用带有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在我的应用程序中运行查询时才会发生

1 个答案:

答案 0 :(得分:0)

它实际上很简单,因为我使用union all我将其更改为union并且它有效。