Taxonomy Lineage

Agileware - December 7, 2005 - 04:33

The Taxonomy Lineage module adds a table to the taxonomy database which allows nodes to be sorted by taxonomy hierarchy. The module adds no new sort function by itself, so simply adding this module will not add functionality. However, it can be used with the Views module, and PHP snippets or custom code may be written to sort, as well.

Problem
The taxonomy hierarchy system, while powerful, cannot easily generate lists of nodes sorted by hierarchy depth.
For example, with a hierarchy structured like:
Parent 1
  Child 1
     Sub-child 1
  Child 2
     Sub-child 2
     Sub-child 3
Parent 2
...

It is very difficult to get those nodes in the right order. So much so, in fact, that it requires a recursive query algorithm.
Solution
In order to solve this, research suggests that an effective solution is the Nested Trees method. An essence, each taxonomy term needs a single field that describes the entire hierarchy in a way that is sortable. The following patch implements such a solution.
Implementation
The patch creates a new table, term_lineage whose sole purpose is to store the hierarchy in a single field. In order to make the field sortable, for each node in the hierarchy a string is constructed. The first part of the string is the term's weight + 10 (to eliminate negative numbers). The second part is the term's name. The third part is a carriage return, which is a character almost guaranteed not to be in the term name and will sort ahead of all possible characters that will be in the title.

When a taxonomy term is updated, its lineage and the lineage of all of its children must be updated. If a taxonomy hierarchy is particularly large, this might be a noticeably slow process, but with a moderate sized hierarchy it took very little time on my system.

About the Developers

This module is maintained by Agileware Pty Ltd, http://www.agileware.net. Please contact us if you require a Drupal theme, custom Drupal module development, Drupal systems integration or have a complex Drupal project. We love Drupal!

Releases

Official releasesDateSizeLinksStatus
5.x-1.42007-Nov-198.06 KBRecommended for 5.xThis is currently the recommended release for 5.x.
4.7.x-1.22007-Jan-208.08 KBRecommended for 4.7.xThis is currently the recommended release for 4.7.x.
Development snapshotsDateSizeLinksStatus
5.x-1.x-dev2007-Jun-198.05 KBDevelopment snapshotDevelopment snapshots are automatically regenerated and their contents can frequently change, so they are not recommended for production use.
4.7.x-1.x-dev2007-Jan-208.08 KBDevelopment snapshotDevelopment snapshots are automatically regenerated and their contents can frequently change, so they are not recommended for production use.
 
 

Drupal is a registered trademark of Dries Buytaert.