Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-07-2022 02:05 PM
Hi,
I want to execute Yen's algorithm using Query annotation in Spring Data. It works but I have problem with mapping the paths:
in option A: I'm mapping to List<NodeName>, it returns all of nodes in one list without separating paths
in option B: I'm using mapping to List<List<NodeName>> and it separates path bur returns only first nodes from all paths as list.
I want to map algorithm result to List<List<NodeName>> like:
[
[a,b,c],
[f,b],
[s,g,t,h],
] etc
Could you please help me how to do it? I was trying using nodes, collect function and also with another class containing only list of NodeName but nothing worked as expected.
Thank you
11-07-2022 02:28 PM
What does your Spring Data entities and repositories look like?
11-07-2022 02:38 PM
Hi, code snippets:
// base class
@Node
public class City {
@Id
@GeneratedValue
private Long id;
@NonNull
private String name;
@NonNull
private String code;
}
// neo4j repository, example returning separated list, always with 1 node
public interface CityRepository extends Neo4jRepository<City, Long> {
@Query("MATCH (source:City {code: 'BCC'}), (target:City {code: 'LAX'})
CALL gds.shortestPath.yens.stream('projection', {
sourceNode: source,
targetNode: target,
k: 20,
relationshipWeightProperty: 'distance'
})
YIELD index, sourceNode, targetNode, nodeIds, path, totalCost, costs
RETURN nodes(path) as path")
List<List<City>> findPaths();
}
11-07-2022 03:17 PM
On the single path there are two types of node like:
city->village->city->village and ideally I want to parse only city nodes, I was trying list comprehension but it also does not work
RETURN [x in nodes(path) WHERE 'City' IN LABELS(x)]
11-11-2022 09:42 AM
Problem solved using neo4j client and custom mapping
All the sessions of the conference are now available online