Advertisement
Guest User

Untitled

a guest
Mar 19th, 2009
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. __________________Method 1__________________
  2.  
  3. post[23](
  4. int_tag=15---------------------
  5. string_content="Some post" |
  6. id_owner=1 |
  7. date=123456) |
  8. |
  9. ----------------------------
  10. |
  11. |
  12. V
  13. tag_assoc[15]( ----> tag_assoc[17]( ---------> tag_assoc[18](
  14. id_tag=12------- | id_tag=20--------- | id_tag=21-----------
  15. id_owner=1 | | id_owner=3 | | id_owner=2 |
  16. int_flink=17---|------ int_flink=18-----|------ int_flink=0 |
  17. ) | ) | ) |
  18. | | |
  19. ----------- | |
  20. | | |
  21. V V V
  22. tag[12]( tag[20]( tag[21](
  23. string_name=cats string_name=dogs string_name=technology
  24. id_owner=20 id_owner=5 id_owner=2
  25. date=123456) date=10000) date=16116)
  26.  
  27. __________________Method 2__________________
  28.  
  29. // The struct in array_tags is id_owner,id_tag.
  30. // The array_tags field is stored in the database as TEXT or VARCHAR
  31.  
  32. post[23](
  33. array_tags=[
  34. 1,12-----------------
  35. 3,20----------------|--------------------------------------------------------------
  36. 2,21----------------|------------------------- |
  37. ] | | |
  38. content="Some post" | | |
  39. owner=1 | | |
  40. date=123456) | | |
  41. | | |
  42. | | |
  43. ----------------- | |
  44. | | |
  45. V V V
  46. tag[12]( tag[20]( tag[21](
  47. string_name=cats string_name=dogs string_name=technology
  48. id_owner=20 id_owner=5 id_owner=2
  49. date=123456) date=10000) date=16116)
  50.  
  51.  
  52. *** What about searching BY tag? We will need a lookup table with either Method 1 or Method 2!
  53.  
  54. __________________Method 3__________________
  55.  
  56. // from: http://stackoverflow.com/questions/20856/how-do-you-recommend-implementing-tags-or-tagging
  57. // also used in the toxi solution: http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html
  58. // This solution will satisfy both
  59. // a) returning all tags for a post
  60. // b) returning all posts for a tag
  61. // Downfall: For both searching by post or searching by tag, or retreiveing all tags for a post,
  62. // the entire tag_assoc table must be searched.
  63.  
  64. post[23](
  65. string_content="Some post"
  66. id_owner=1
  67. date=123456)
  68. ^
  69. |
  70. -------------------------------------------------------------------------------
  71. | | |
  72. tag_assoc[15]( | tag_assoc[17]( | tag_assoc[18]( |
  73. id_post=23----- id_post=17-------- id_post=17----------
  74. id_owner=1 id_owner=3 id_owner=2
  75. id_tag=12------| id_tag=20--------- int_tag=21----------
  76. ) | ) | ) |
  77. | | |
  78. ----------- | |
  79. | | |
  80. V V V
  81. tag[12]( tag[20]( tag[21](
  82. string_name=cats string_name=dogs string_name=technology
  83. id_owner=20 id_owner=5 id_owner=2
  84. date=123456) date=10000) date=16116)
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement