In this example, a multi-level tree structure
is used to index event nodes (here Event1
, Event2
and Event3
,
in this case with a YEAR-MONTH-DAY granularity, making this a timeline indexing structure.
However, this approach should work for a wide range of multi-level ranges.
The structure follows a couple of rules:
VALUE
relationship.
The graph below depicts a structure with 3 Events being attached to an index structure at different leafs.
Here, only the events indexed under one leaf (2010-12-31) are returned.
The query only needs one path segment rootPath
(color Green
) through the index.
Query.
START root=node:node_auto_index(name = 'Root') MATCH rootPath=root-[:`2010`]->()-[:`12`]->()-[:`31`]->leaf, leaf-[:VALUE]->event RETURN event.name ORDER BY event.name ASC
Returning all events on the date 2010-12-31, in this case Event1
and Event2
Try this query live. (1) {"name":"Y11M01"} (2) {"name":"Y10M12D31"} (3) {"name":"Y10M12"} (4) {"name":"Event2"} (5) {"name":"Y11M11D02"} (6) {"name":"Y11"} (7) {"name":"Event3"} (8) {"name":"Y10"} (9) {"name":"Root"} (10) {"name":"Event1"} (11) {"name":"Y11M01D01"} (12) {"name":"Y11M12D03"} (1)-[:01]->(11) {} (1)-[:02]->(5) {} (1)-[:03]->(12) {} (2)-[:NEXT]->(11) {} (2)-[:VALUE]->(10) {} (2)-[:VALUE]->(4) {} (3)-[:31]->(2) {} (5)-[:NEXT]->(12) {} (6)-[:01]->(1) {} (8)-[:12]->(3) {} (9)-[:2010]->(8) {} (9)-[:2011]->(6) {} (11)-[:NEXT]->(5) {} (11)-[:VALUE]->(4) {} (12)-[:VALUE]->(7) {} START root=node:node_auto_index(name = 'Root') MATCH rootPath=root-[:`2010`]->()-[:`12`]->()-[:`31`]->leaf, leaf-[:VALUE]->event RETURN event.name ORDER BY event.name ASC
In this case, the range goes from the first to the last leaf of the index tree. Here,
startPath
(color Greenyellow
) and endPath
(color Green
) span up the range, valuePath
(color Blue
) is then connecting the leafs, and the values can
be read from the middle
node, hanging off the values
(color Red
) path.
Query.
START root=node:node_auto_index(name = 'Root') MATCH startPath=root-[:`2010`]->()-[:`12`]->()-[:`31`]->startLeaf, endPath=root-[:`2011`]->()-[:`01`]->()-[:`03`]->endLeaf, valuePath=startLeaf-[:NEXT*0..]->middle-[:NEXT*0..]->endLeaf, values=middle-[:VALUE]->event RETURN event.name ORDER BY event.name ASC
Returning all events between 2010-12-31 and 2011-01-03, in this case all events.
Try this query live. (1) {"name":"Y11M01"} (2) {"name":"Y10M12D31"} (3) {"name":"Y10M12"} (4) {"name":"Event2"} (5) {"name":"Y11M11D02"} (6) {"name":"Y11"} (7) {"name":"Event3"} (8) {"name":"Y10"} (9) {"name":"Root"} (10) {"name":"Event1"} (11) {"name":"Y11M01D01"} (12) {"name":"Y11M12D03"} (1)-[:01]->(11) {} (1)-[:02]->(5) {} (1)-[:03]->(12) {} (2)-[:NEXT]->(11) {} (2)-[:VALUE]->(10) {} (2)-[:VALUE]->(4) {} (3)-[:31]->(2) {} (5)-[:NEXT]->(12) {} (6)-[:01]->(1) {} (8)-[:12]->(3) {} (9)-[:2010]->(8) {} (9)-[:2011]->(6) {} (11)-[:NEXT]->(5) {} (11)-[:VALUE]->(4) {} (12)-[:VALUE]->(7) {} START root=node:node_auto_index(name = 'Root') MATCH startPath=root-[:`2010`]->()-[:`12`]->()-[:`31`]->startLeaf, endPath=root-[:`2011`]->()-[:`01`]->()-[:`03`]->endLeaf, valuePath=startLeaf-[:NEXT*0..]->middle-[:NEXT*0..]->endLeaf, values=middle-[:VALUE]->event RETURN event.name ORDER BY event.name ASC
Here, the query range results in partly shared paths when querying the index,
making the introduction of and common path segment commonPath
(color Black
) necessary, before spanning up startPath
(color Greenyellow
) and
endPath
(color Darkgreen
) . After that, valuePath
(color Blue
) connects the leafs and the indexed values are returned off values
(color Red
) path.
Query.
START root=node:node_auto_index(name = 'Root') MATCH commonPath=root-[:`2011`]->()-[:`01`]->commonRootEnd, startPath=commonRootEnd-[:`01`]->startLeaf, endPath=commonRootEnd-[:`03`]->endLeaf, valuePath=startLeaf-[:NEXT*0..]->middle-[:NEXT*0..]->endLeaf, values=middle-[:VALUE]->event RETURN event.name ORDER BY event.name ASC
Returning all events between 2011-01-01 and 2011-01-03, in this case Event2
and Event3
.
Try this query live. (1) {"name":"Y11M01"} (2) {"name":"Y10M12D31"} (3) {"name":"Y10M12"} (4) {"name":"Event2"} (5) {"name":"Y11M11D02"} (6) {"name":"Y11"} (7) {"name":"Event3"} (8) {"name":"Y10"} (9) {"name":"Root"} (10) {"name":"Event1"} (11) {"name":"Y11M01D01"} (12) {"name":"Y11M12D03"} (1)-[:01]->(11) {} (1)-[:02]->(5) {} (1)-[:03]->(12) {} (2)-[:NEXT]->(11) {} (2)-[:VALUE]->(10) {} (2)-[:VALUE]->(4) {} (3)-[:31]->(2) {} (5)-[:NEXT]->(12) {} (6)-[:01]->(1) {} (8)-[:12]->(3) {} (9)-[:2010]->(8) {} (9)-[:2011]->(6) {} (11)-[:NEXT]->(5) {} (11)-[:VALUE]->(4) {} (12)-[:VALUE]->(7) {} START root=node:node_auto_index(name = 'Root') MATCH commonPath=root-[:`2011`]->()-[:`01`]->commonRootEnd, startPath=commonRootEnd-[:`01`]->startLeaf, endPath=commonRootEnd-[:`03`]->endLeaf, valuePath=startLeaf-[:NEXT*0..]->middle-[:NEXT*0..]->endLeaf, values=middle-[:VALUE]->event RETURN event.name ORDER BY event.name ASC
Copyright © 2013 Neo Technology