コード例 #1
0
        public async Task <IActionResult> GetHot()
        {
            ObjectId currentUser = ObjectId.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            DateTime dateTime          = DateTime.UtcNow;
            var      beforeLimit       = dateTime.AddDays(-5);
            var      beforeLimitString = beforeLimit.ToString("yyyy-MM-dd") + "T" + beforeLimit.ToString("HH:mm:ss.ff") + "Z";
            var      query             = _neoContext.Cypher
                                         .Match($"(u:User)-[up:UPVOTED]->(t:Ticket)")
                                         .Where($"(up.Time > datetime('{beforeLimitString}')) AND (NOT (u)-[:CREATED]->(t))")
                                         .Match($"(c)-[:CREATED]->(t)")
                                         .With($"count(up) as ups, c.Username AS username, c.Id as userId, t")
                                         .OptionalMatch($"(u2:User)-[down:DOWNVOTED]->(t)")
                                         .With($"ups, (ups * 10 - coalesce(count(down),0) * 2) as rating, username, userId, t.Id as TicketId, t.Title as title")
                                         .Where("rating >= 0")
                                         .Return((username, rating, userId, TicketId, title) => new
            {
                Username = username.As <string>(),
                Rating   = rating.As <int>(),
                UserId   = userId.As <string>(),
                TicketId = TicketId.As <string>(),
                Title    = title.As <string>()
            })
                                         .OrderByDescending("rating", "ups")
                                         .Limit(5);
            var queryText = query.Query.DebugQueryText;

            return(Ok(await query.ResultsAsync));
        }
コード例 #2
0
        public async Task <IActionResult> GetRecommended()
        {
            ObjectId currentUser = ObjectId.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            DateTime dateTime          = DateTime.UtcNow;
            var      beforeLimit       = dateTime.AddDays(-14);
            var      beforeLimitString = beforeLimit.ToString("yyyy-MM-dd") + "T" + beforeLimit.ToString("HH:mm:ss.ff") + "Z";
            var      query             = _neoContext.Cypher
                                         .Match($"(u:User {{Id: '{currentUser}'}})-[:INTEREST]->(rec:Topic)<-[:ON_TOPIC]-(t:Ticket)")
                                         .Where($"(t.Time > datetime('{beforeLimitString}')) AND (NOT (u)-[:CREATED]->(t))")
                                         .Match($"(c)-[:CREATED]->(t)")
                                         .With($"c.Username AS username, c.Id as userId, t.Id as TicketId, t.Title as title")
                                         .Return((username, userId, TicketId, title) => new
            {
                Username = username.As <string>(),
                UserId   = userId.As <string>(),
                TicketId = TicketId.As <string>(),
                Title    = title.As <string>()
            })
                                         .Limit(10);
            var queryText = query.Query.DebugQueryText;


            return(Ok(await query.ResultsAsync));
        }