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.
Graph
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.
Graph
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
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 canan
be read from the middle
node, hanging off the values
(color Red
) path.
Graph
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.
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.
Graph
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
.
Copyright © 2012 Neo Technology