6.13. A multilevel indexing structure (path tree)
In this example, a multi-level tree structure
is used to index event nodes (here
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:
Events can be indexed multiple times by connecting the indexing structure leafs with the events via a
- The querying is done in a path-range fashion. That is, the start- and end path from the indexing root to the start and end leafs in the tree are calculated
- Using Cypher, the queries following different strategies can be expressed as path sections and put together using one single query.
The graph below depicts a structure with 3 Events being attached to an index structure at different leafs.
Return zero range
Here, only the events indexed under one leaf (2010-12-31) are returned.
The query only needs one path segment
Green) through the index.
MATCH rootPath=(root)-[:`2010`]->()-[:`12`]->()-[:`31`]->(leaf),(leaf)-[:VALUE]->(event) WHERE root.name = 'Root' RETURN event.name ORDER BY event.name ASC
Returning all events on the date 2010-12-31, in this case
Return the full range
In this case, the range goes from the first to the last leaf of the index tree. Here,
Green) span up the range,
Blue) is then connecting the leafs, and the values can
be read from the
middle node, hanging off the
MATCH startPath=(root)-[:`2010`]->()-[:`12`]->()-[:`31`]->(startLeaf), endPath=(root)-[:`2011`]->()-[:`01`]->()-[:`03`]->(endLeaf), valuePath=(startLeaf)-[:NEXT*0..]->(middle)-[:NEXT*0..]->(endLeaf), vals=(middle)-[:VALUE]->(event) WHERE root.name = 'Root' RETURN event.name ORDER BY event.name ASC
Returning all events between 2010-12-31 and 2011-01-03, in this case all events.