You are here

README.txt in Taxonomy Edge 6

Same filename and directory in other branches
  1. 8 README.txt
  2. 7.2 README.txt
  3. 7 README.txt
Description
-----------

Selecting all children of a given taxonomy term can be a pain.
This module makes it easier to do this, by maintaining a complete list of edges
for each term using the adjecency matrix graph theory:
  http://en.wikipedia.org/wiki/Adjacency_matrix

Visit the project page:
  http://drupal.org/project/taxonomy_edge


Requirements
------------
Taxonomy module (and the Views module for the Views Taxonomy Edge module)


Installation
------------
Place in modules folder and enable it from /admin/build/modules

Apply the core patch if you like:
%> cd /path/to/drupal
%> patch -p1 < sites/all/modules/taxonomy_edge/taxonomy-<drupal-version>.patch



Maintenance
-----------
Rebuild edges from /admin/content/taxonomy/edge

Edges can also be rebuild through cron if a hook_cronapi() compatible cron module is installed (Elysia Cron, Ultimate Cron, etc.)

Rebuilding of edges can be necessary if the table gets out of sync.


SQL
------

The following select statements can be used as help or inspiration to use the term_edge table:

Get the top level term IDs for the term 14:

SELECT DISTINCT e2.parent
FROM term_edge e
JOIN term_edge e2 ON e2.tid = e.tid AND e2.distance = e.distance - 1 AND e2.parent <> e.parent
WHERE e.tid = 14
AND e.parent = 0
AND e.vid = e2.vid


Generate a list of materialized paths for each term in vocabulary vid:1, in the correct order:

SELECT d2.*, e2.parent, e2.distance,
(
SELECT CONCAT('"', GROUP_CONCAT(d.name ORDER BY e.distance DESC SEPARATOR '/'), '"') AS path FROM term_edge e JOIN term_data d ON e.parent = d.tid WHERE e.tid = e2.tid ORDER BY e.distance DESC
) AS path,
(
SELECT GROUP_CONCAT(d.weight + 1500, '    ', d.name ORDER BY e.distance DESC SEPARATOR '    ') AS path FROM term_edge e JOIN term_data d ON e.parent = d.tid WHERE e.tid = e2.tid ORDER BY e.distance DESC
) AS sort_path
FROM term_edge e2
JOIN term_data d ON d.tid = e2.tid
WHERE e2.vid = 1
AND e2.parent = 0
ORDER BY sort_path;


Get all parents of a term tid:12

SELECT * FROM term_edge WHERE tid = 12 AND distance > 0;


Get all children of a term tid:12

SELECT * FROM term_edge WHERE parent = 12;



Misc.
-----
Other popular alternatives to the adjecency matrix model are the nested set and materialized path.

Nested set (http://en.wikipedia.org/wiki/Nested_set_model):
 - Advantages
   - Fast retrieval of sorted tree.
 - Disadvantages:
   - Complex.
   - Can be heavy on insert/update (can be mitigated with gaps, but increases complexity).

Materialized path (http://www.dba-oracle.com/t_sql_patterns_trees.htm):
 - Advantages
   - Simple to understand.
 - Disadvantages:
   - Can be heavy on select/insert/update due to string compare.
   - Requires multiple queries for proper use of indexes on subtree selection.
   - Depth limit (due to index size limitation).

File

README.txt
View source
  1. Description
  2. -----------
  3. Selecting all children of a given taxonomy term can be a pain.
  4. This module makes it easier to do this, by maintaining a complete list of edges
  5. for each term using the adjecency matrix graph theory:
  6. http://en.wikipedia.org/wiki/Adjacency_matrix
  7. Visit the project page:
  8. http://drupal.org/project/taxonomy_edge
  9. Requirements
  10. ------------
  11. Taxonomy module (and the Views module for the Views Taxonomy Edge module)
  12. Installation
  13. ------------
  14. Place in modules folder and enable it from /admin/build/modules
  15. Apply the core patch if you like:
  16. %> cd /path/to/drupal
  17. %> patch -p1 < sites/all/modules/taxonomy_edge/taxonomy-.patch
  18. Maintenance
  19. -----------
  20. Rebuild edges from /admin/content/taxonomy/edge
  21. Edges can also be rebuild through cron if a hook_cronapi() compatible cron module is installed (Elysia Cron, Ultimate Cron, etc.)
  22. Rebuilding of edges can be necessary if the table gets out of sync.
  23. SQL
  24. ------
  25. The following select statements can be used as help or inspiration to use the term_edge table:
  26. Get the top level term IDs for the term 14:
  27. SELECT DISTINCT e2.parent
  28. FROM term_edge e
  29. JOIN term_edge e2 ON e2.tid = e.tid AND e2.distance = e.distance - 1 AND e2.parent <> e.parent
  30. WHERE e.tid = 14
  31. AND e.parent = 0
  32. AND e.vid = e2.vid
  33. Generate a list of materialized paths for each term in vocabulary vid:1, in the correct order:
  34. SELECT d2.*, e2.parent, e2.distance,
  35. (
  36. SELECT CONCAT('"', GROUP_CONCAT(d.name ORDER BY e.distance DESC SEPARATOR '/'), '"') AS path FROM term_edge e JOIN term_data d ON e.parent = d.tid WHERE e.tid = e2.tid ORDER BY e.distance DESC
  37. ) AS path,
  38. (
  39. SELECT GROUP_CONCAT(d.weight + 1500, ' ', d.name ORDER BY e.distance DESC SEPARATOR ' ') AS path FROM term_edge e JOIN term_data d ON e.parent = d.tid WHERE e.tid = e2.tid ORDER BY e.distance DESC
  40. ) AS sort_path
  41. FROM term_edge e2
  42. JOIN term_data d ON d.tid = e2.tid
  43. WHERE e2.vid = 1
  44. AND e2.parent = 0
  45. ORDER BY sort_path;
  46. Get all parents of a term tid:12
  47. SELECT * FROM term_edge WHERE tid = 12 AND distance > 0;
  48. Get all children of a term tid:12
  49. SELECT * FROM term_edge WHERE parent = 12;
  50. Misc.
  51. -----
  52. Other popular alternatives to the adjecency matrix model are the nested set and materialized path.
  53. Nested set (http://en.wikipedia.org/wiki/Nested_set_model):
  54. - Advantages
  55. - Fast retrieval of sorted tree.
  56. - Disadvantages:
  57. - Complex.
  58. - Can be heavy on insert/update (can be mitigated with gaps, but increases complexity).
  59. Materialized path (http://www.dba-oracle.com/t_sql_patterns_trees.htm):
  60. - Advantages
  61. - Simple to understand.
  62. - Disadvantages:
  63. - Can be heavy on select/insert/update due to string compare.
  64. - Requires multiple queries for proper use of indexes on subtree selection.
  65. - Depth limit (due to index size limitation).