You are here

README.txt in Taxonomy Edge 7.2

Same filename and directory in other branches
  1. 8 README.txt
  2. 6 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/sandbox/gielfeldt/1090284


Requirements
------------
Currently only MySQL is supported.
Elysia Cron or Parallel Cron (or other hook_cronapi() compatible cron system) for cronjob to work.


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, Parallel 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 each term in vocabulary vid:1:

SELECT te.tid, h.tid AS top_tid
FROM term_edge te
JOIN term_hierarchy h ON te.parent = h.tid
JOIN term_data d ON d.tid = te.tid
WHERE h.parent = 0
AND d.vid = 1;


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_hierarchy h ON h.tid = e2.parent
JOIN term_data d2 ON e2.tid = d2.tid
WHERE d2.vid = 1
AND h.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.

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.

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/sandbox/gielfeldt/1090284
  9. Requirements
  10. ------------
  11. Currently only MySQL is supported.
  12. Elysia Cron or Parallel Cron (or other hook_cronapi() compatible cron system) for cronjob to work.
  13. Installation
  14. ------------
  15. Place in modules folder and enable it from /admin/build/modules
  16. Apply the core patch if you like:
  17. %> cd /path/to/drupal
  18. %> patch -p1 < sites/all/modules/taxonomy_edge/taxonomy-.patch
  19. Maintenance
  20. -----------
  21. Rebuild edges from /admin/content/taxonomy/edge
  22. Edges can also be rebuild through cron if a hook_cronapi() compatible cron module is installed (Elysia Cron, Parallel Cron, etc.)
  23. Rebuilding of edges can be necessary if the table gets out of sync.
  24. SQL
  25. ------
  26. The following select statements can be used as help or inspiration to use the term_edge table:
  27. Get the top level term IDs for each term in vocabulary vid:1:
  28. SELECT te.tid, h.tid AS top_tid
  29. FROM term_edge te
  30. JOIN term_hierarchy h ON te.parent = h.tid
  31. JOIN term_data d ON d.tid = te.tid
  32. WHERE h.parent = 0
  33. AND d.vid = 1;
  34. Generate a list of materialized paths for each term in vocabulary vid:1, in the correct order:
  35. SELECT d2.*, e2.parent, e2.distance,
  36. (
  37. 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
  38. ) AS path,
  39. (
  40. 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
  41. ) AS sort_path
  42. FROM term_edge e2
  43. JOIN term_hierarchy h ON h.tid = e2.parent
  44. JOIN term_data d2 ON e2.tid = d2.tid
  45. WHERE d2.vid = 1
  46. AND h.parent = 0
  47. ORDER BY sort_path;
  48. Get all parents of a term tid:12
  49. SELECT * FROM term_edge WHERE tid = 12 AND distance > 0;
  50. Get all children of a term tid:12
  51. SELECT * FROM term_edge WHERE parent = 12;
  52. Misc.
  53. -----
  54. Other popular alternatives to the adjecency matrix model are the nested set and materialized path.
  55. Nested set (http://en.wikipedia.org/wiki/Nested_set_model):
  56. - Advantages
  57. - Fast retrieval of sorted tree.
  58. - Disadvantages:
  59. - Complex.
  60. - Can be heavy on insert/update.
  61. Materialized path (http://www.dba-oracle.com/t_sql_patterns_trees.htm):
  62. - Advantages
  63. - Simple to understand.
  64. - Disadvantages:
  65. - Can be heavy on select/insert/update due to string compare.