Prev |  | Next

## 7.14. A multilevel indexing structure (path tree)

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:

- Events can be indexed multiple times by connecting the indexing structure leafs with the events via a `VALUE` relationship.
- 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.

Graph

### 7.14.1. Return zero range

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`

Result

event.name
2 rows
0 ms
`"Event1"`
`"Event2"`

### 7.14.2. Return the full range

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.

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.

Result

event.name
4 rows
0 ms
`"Event1"`
`"Event2"`
`"Event2"`
`"Event3"`

### 7.14.3. Return partly shared path ranges

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`.

Result

event.name
2 rows
0 ms
`"Event2"`
`"Event3"`

Copyright © 2012 Neo Technology

Prev | Up | Next
| Home |