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.

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.

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.
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 (plus an offset 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.

Supporting organizations: 

Project Information