Simple,fast and easy to understand example of how to build nested sets
for Drupal taxonomies (or any other adjacency list for that matter).
Two versions a are available, present in branches master and hybrid (hybrid being by far the fastest).
Supports multiple parents.
This module servers as an example of how nested sets could be implemented. The goal is to provide an easy to understand implementation.
Experiences and ideas might be offered to the module Leftandright - Nested Set Taxonomy
Master
A 3-step process implemented as a Drupal batch job.
- Sort and count depth of all terms (we need this to perform step 2)
- Count children recursively for all terms (backwards through depth)
- Traverse entire tree and generate left + right values
Go to the edit page of a vocabulary to generate the nested sets.
To find a sub tree afterwards, e.g. for all terms under tid:14
SELECT c.tid
FROM taxonomy_mptt parent
INNER JOIN taxonomy_mptt children ON children.lft BETWEEN parent.lft AND parent.rgt
WHERE parent.tid = 14