www.webdeveloper.com
Results 1 to 10 of 10

Thread: Tagging solution question

  1. #1
    Join Date
    May 2010
    Posts
    136

    Tagging solution question

    The idea of tagging solution(book mark, search,blogs, facebook) is not clear to me. So in simple explanation what is a tagging solution? Is the database structure below an example of tag solution? Thanks.

    Code:
    CREATE TABLE article (
        id INTEGER NOT NULL autoincrement,
        modified TIMESTAMP,
        content TEXT
        ...
        PRIMARY KEY (id)
    );
    
    CREATE TABLE keyword (
        word VARCHAR(20),
        article_id INTEGER, /* references article.id
        relevance FLOAT DEFAULT 0.5, /* allow users to record relevance of keyword to article*/
        PRIMARY KEY (word, article_id)
    );
    
    CREATE TEMPORARY TABLE search (
        word VARCHAR(20),
        PRIMARY KEY (word)
    );
    Let say I have key words 'Apple' and 'Orange' stored on a a column they have reference column (article_id). When I type something on a search box, let say I type "Look for apple and orange", then I explode that and search on key word table with reference(article_id), this is tag search based right?
    Last edited by anishgiri; 02-23-2012 at 08:40 PM.

  2. #2
    Join Date
    Feb 2012
    Location
    Tallahassee, FL
    Posts
    280
    I have to be honest, I am not 100% sure but my understanding is if you have a db with articles, each article has a field for keywords. You would then query with something like:

    SELECT * FROM $db.$table WHERE keywords LIKE '%$searchstring%';

  3. #3
    Join Date
    May 2010
    Posts
    136
    Thanks for some information. Any body else have an idea of this? Thanks...

  4. #4
    Join Date
    Nov 2002
    Posts
    2,632
    Code:
    CREATE TABLE article (
        id INTEGER NOT NULL autoincrement,
        modified TIMESTAMP,
        content TEXT
        ...
        PRIMARY KEY (id)
    );
    
    CREATE TABLE keyword (
        word VARCHAR(20),
        article_id INTEGER,
        relevance FLOAT DEFAULT 0.5, /* allow users to record relevance of keyword to article*/
        PRIMARY KEY (word, article_id)
    );
    Roughly

    Code:
    Select *
    FROM article, keyword
    WHERE $word = keyword.word and keyword.article_id = article.id
    GROUP BY relevance;
    $word being the word you are looking for. You would modify the where statement with "and" if you are searching for more than one word. Hint: Use an array.

  5. #5
    Join Date
    May 2010
    Posts
    136
    Quote Originally Posted by NoEffinWay View Post
    I have to be honest, I am not 100% sure but my understanding is if you have a db with articles, each article has a field for keywords. You would then query with something like:

    SELECT * FROM $db.$table WHERE keywords LIKE '%$searchstring%';
    So what is better an article table that include key word id, or key word table that includes article id?

    @spufi thanks for the post...

  6. #6
    Join Date
    Feb 2012
    Location
    Tallahassee, FL
    Posts
    280
    I wouldnt try to make a relational table with this. I would have a keyword field within the article table.

  7. #7
    Join Date
    May 2010
    Posts
    136
    Quote Originally Posted by NoEffinWay View Post
    I wouldnt try to make a relational table with this. I would have a keyword field within the article table.
    The keyword field will contain keyword values separated by comma? Something like "keyword1, Keyword2, Keyword3"?

  8. #8
    Join Date
    Feb 2012
    Location
    Tallahassee, FL
    Posts
    280
    Yeah. Then you can do a like search. Now if you wanted to only have specific keywords, then maybe a separate table but if you want to just add keyword, just do it in a new field.

  9. #9
    Join Date
    May 2010
    Posts
    136
    Quote Originally Posted by NoEffinWay View Post
    Yeah. Then you can do a like search. Now if you wanted to only have specific keywords, then maybe a separate table but if you want to just add keyword, just do it in a new field.
    But is it, a field containing keywords separated by comma against data base normalization?

  10. #10
    Join Date
    Jan 2009
    Posts
    3,346
    Quote Originally Posted by NoEffinWay View Post
    Yeah. Then you can do a like search. Now if you wanted to only have specific keywords, then maybe a separate table but if you want to just add keyword, just do it in a new field.
    What happens if you need to remove a keyword? Pull the whole field and edit? LIKE queries are much more expensive than a simple join...relational would be best in this case.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles