Exemplo n.º 1
0
        public async Task <TrackFinderResponse> FindTrack(TrackFinderRequest model)
        {
            var session = _driver.AsyncSession(WithDatabase);

            try
            {
                return(await session.ReadTransactionAsync(async transaction =>
                {
                    var cursor = await transaction.RunAsync(@"
MATCH (start:Place {name: $name1}), (end:Place {name: $name2})
CALL gds.beta.shortestPath.dijkstra.stream({
  nodeProjection: 'Place',
  relationshipProjection: {
    Distance: {
      type: 'Path',
      properties: 'distance',
      orientation: 'UNDIRECTED'
    }
  },
  sourceNode: id(start),
  targetNode: id(end),
  relationshipWeightProperty: 'distance'
})
YIELD index, sourceNode, targetNode, totalCost, nodeIds, costs
RETURN
    index,
    gds.util.asNode(sourceNode).name AS sourceNodeName,
    gds.util.asNode(targetNode).name AS targetNodeName,
    totalCost,
    [nodeId IN nodeIds | gds.util.asNode(nodeId).name] AS nodeNames,
    costs
ORDER BY index
                        ", new { name1 = model.From, name2 = model.To }
                                                            );

                    var list = await cursor.ToListAsync(record => new TrackFinderResponse
                    {
                        TotalCost = record["totalCost"].As <double>(),
                        NodeNames = record["nodeNames"].As <List <object> >(),
                        Costs = record["costs"].As <List <object> >()
                    }
                                                        );
                    return list.Count > 0 ? list[0] : null;
                }));
            }
            finally
            {
                await session.CloseAsync();
            }
        }
 public async Task <TrackFinderResponse> FindTrack(TrackFinderRequest model)
 {
     return(await _neo4JRepository.FindTrack(model));
 }