Tag Cloud, but on the back end.

Discussion in 'Programming' started by t0keym0n, Apr 19, 2008.

  1. #1
    Hi :)

    I have been tryin to build an application that will utilize taging.

    my question is, when adding multiple tags into one data base field,
    how to do I then query the tags and apply links and sorting?

    an example of what I want is here at live journal

    in the journal entry form, it has one entry field for tags.
    [​IMG]

    but then on the front end, it shows all my tags, and apply links accordingly.
    [​IMG]

    any chance any one knows how to achive this?

    do I store all the tags into one data base field? do I some how separate them? how do I count them all? could explain the basic logic behind creating this?
     
    t0keym0n, Apr 19, 2008 IP
  2. dshuck

    dshuck Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    We do this on InstantSpot by having the following tables (roughly)
    Content
    Tag
    ContentTag

    Where ContentTag is a relational table that links a specific Tag to a Content object by joining on the columns ContentId and TagId. Then, in our data model, one of the children of a Content object is Tag, which can be accessed using Content.getTagQuery(), Content.getTagArray() methods on a particular Content object. We actually take it quite a bit further including Tag types, and keeping a relationship of which tags belong to which sites/users, but I have a feeling the general concept above is what you were asking. Here are some of our implementations:

    The tag cloud on a particular blog can be seen on my Spot on the bottom of the left nav:
    http://daveshuck.instantspot.com/blog/

    Here is a tag cloud for the entire network using the same objects.
    http://www.instantspot.com/browse

    hth
     
    dshuck, Apr 20, 2008 IP
  3. t0keym0n

    t0keym0n Greenhorn

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    ahh good, I'm glad some one understood, it took me a while to really find any information on this, let alone to form my question properly. :)

    [​IMG]
    I have found alot of the popular sites use that 3 table set up.
    a small question, what purpose does the middle table really serve?

    [​IMG]
    I've totally done the 2 table set up and understand how to implement that, but I just don't understand what the 3rd middle table serves.

    and my second question is, how do you apply these tags to an insert action. (a blog post)

    I've been reading a lot on this database schema, but every one has tutorials on how to search or query the table, not how they insert the info.

    on live journal they have one field to type tags into, I have no clue on how you could achive that method in CF8. do I count every word in that fiorm field, and create a new tag entry for that? the proper syntax and workflow eludes me :(

    p/s I guess I'm not really tryin to build a tag cloud, the cloud is just a resulting way to search the blog post, I really want to know how to set up a tag entry system over the cloud.
     
    t0keym0n, Apr 22, 2008 IP
  4. dshuck

    dshuck Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well the simple answer to "I just don't understand what the 3rd middle table serves" is the fact that 3 tables will allow you to support a many-to-many relationship where a bookmark can not only have multiple tags, but each tag could also have multiple bookmarks. Otherwise, you are binding a tag to a bookmark, which would be terribly inflexible.

    Here is how I typically manage an insert of a new record. In our case it is blog entries, but bookmarks for you...

    * Create the blog entry record returning the new ContentId (Content.getContentId())
    * In the case of an update rather than a create, I delete all ContentTag records where ContentId is the current ContentId so that we can reinsert them in the case of a change.
    * On our form we use comma separated tags, so I then loop through the list simply using <cfloop list="....
    * On each iteration, I do a query to find out if the tag exists. If it does, I return the Tag record. Otherwise I insert a new Tag record and return the new Tag object. In either case I now have a Tag.getTagId(). I then create a new ContentTag object and populate it with Content.getContentId() and Tag.getTagId() and persist it to the ContentTag table.

    You mentioned that you are doing every word. If you want to do that you can take the same approach but just do <cfloop list="#whateverfield#" index="i" delimeter=" ".....

    If you need any further clarification let me know.
     
    dshuck, Apr 22, 2008 IP
  5. t0keym0n

    t0keym0n Greenhorn

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #5
    the above worked great! thanks, I have set up the blog tag entry system and it works perfectly.

    my next question would be, how do you edit a blog post.

    If I populate a form field with my database entry info, how would I fill a text field with my tag entries?

    because I can't do THIS:

    <cfinput type="text" name="theBlogTags" value="
    			<cfoutput query="rsBlogs">                
                               <cfquery name="rsMaps" datasource="#slyDSN#">
                                  SELECT tblblogtagmap.theBlogID,
                                             tblblogtagmap.theTagID,
                                             tblblogtagmap.theMapID
                                  FROM tblblogtagmap
                                  WHERE tblblogtagmap.theBlogID = #rsBlogs.theBlogID#
                                </cfquery>	
                                <cfloop query="rsMaps" >
                                  <cfquery name="rsTags" datasource="#slyDSN#">
                                    SELECT tblblogtag.theTagID,
                                             tblblogtag.theTagName
                                    FROM tblblogtag
                                    WHERE tblblogtag.theTagID = #rsMaps.theTagID#
                                  </cfquery>
                                  
                                  #rsTags.theTagName#
                                 </cfloop>
    			</cfoutput>" size="71" required="yes" message="You must add one Tag">
    Code (markup):
    what is a standard-ish way of editing your blog post, and maintaining your tags or adding/deleting tags from a post?
     
    t0keym0n, May 13, 2008 IP