--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
public Iterable expand(Path path, BranchState state) { // for the start node return all outgoing connections if (path.length() < 1){ return path.endNode().getRelationships(Direction.OUTGOING); } else { // for all consecutive nodes only return relations with same ID and with the next sequence number
// get previuos sequence Integer seq = (Integer)path.lastRelationship().getProperty(SEQUENCE); // increase the sequence by one to find the next sequence Integer nextSeq = seq+1;
// get ID Object lastID = path.lastRelationship().getProperty(ID);
ArrayList<Relationship> result = new ArrayList<>();
// get all outgoing rleationsships for end node Iterable<Relationship> trips = path.endNode().getRelationships(Direction.OUTGOING, TRIP); for (Relationship trip : trips) { // only return is ID is equal and sequence is the next sequence if (lastID.equals(rel.getProperty(ID, null))){ if (nextSeq.equals((Integer)rel.getProperty(SEQUENCE, null))){ result.add(rel); } }
return result;
}}
public Iterable expand(Path path, BranchState state) {
Node end = path.endNode(); // return all at the first step if (path.length() < 1){ return end.getRelationships(Direction.OUTGOING); } else { // for all others get the next step from the index relIx Relationship endRel = path.lastRelationship(); Integer lastSeq= (Integer)endRel.getProperty(SEQUENCE) + 1; Object lastID = endRel.getProperty(ID); String id_seq = lastID + "_" + lastSeq;
IndexHits<Relationship> rels = relIx.get("id_seq", imo_seq, end, null); return (Iterable) rels.iterator(); }}
I have modeled the problem in alternative way, like suggested by Michael. This are trips for the Truck 'Meyer'.
How ever while playing with it, I am facing some problems:
I want to know all trips from Hamburg to Munich. And I want to get the sequence of city names for these trips. And I want only direct trips (ever stop should occur only once).
I did not mange to 'join in' the city names so I stored the city names as properties on the sequence nodes. With that I ended up with this query:
However performance wise, I do not get big advantages above my optimized other approach.
Any tips?
Here is the a link to the console populated with the test graph: http://console.neo4j.org/r/yv6ex1
(city:Location {name: 'Munich'})<-[ra:ARRIVED_AT_2015week4]-(e0:Event:Arrival)-[rb:ARRIVED_ON_2015week4]->(d:Day {printable_date: '2015.01.25'})
(city:Location {name: 'Munich'})-[rc:DEPARTED_AT_2015week5]->(e1:Event:Departure)<-[rd:DEPARTED_ON_2015week5]->(d:Day {printable_date: '2015.01.26'})
(t:Truck {license_plate: 'ABC123'})<-[:TRIP_2015week5]-(e1:Event:Departure)<-[:TRIP_2015week4]-(e0:Event:Arrival) // direction in sequence
MATCH (src:Location {name: 'Munich'})-->(e0:Event:Departure)
WITH e0
MATCH (e1:Event:Arrival)-->(dst:Location {name: 'Hamburg'})
WITH e0, e1 MATCH p = (e0)-[r*1..]->(e1)
WITH DISTINCT p RETURN p ORDER BY LENGTH(p) DESC;
I do not fully understand why you put the week in the relationship type.
As for your query: it does not prevent circles. Try to find a route from Hamburg to Munich and you will get:
1. Hamburg --> Bremen --> Munich
2. Hamburg --> Hannover --> Munich
3. Hamburg --> Hannover --> Munich --> Frankfurt --> Munich
4. Hamburg --> Hannover --> Munich --> Frankfurt --> Munich --> Hannover --> Hamburg --> Bremen --> Munich
The last two results contain circles.