Hi,
I'm trying to implement a "related articles" module, like Youtube's "Related Videos", into our own intranet. I have those following tables;
Code:
CREATE TABLE `articles` (
`article_id` SMALLINT(6) UNSIGNED NOT NULL AUTO_INCREMENT,
`category_id` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',
`title` VARCHAR(200),
PRIMARY KEY (`article_id`)
)ENGINE=MyISAM
AUTO_INCREMENT=1 CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
CREATE TABLE `tags` (
`tag_id` MEDIUMINT(9) UNSIGNED NOT NULL AUTO_INCREMENT,
`title` VARCHAR(50) COLLATE utf8_general_ci NOT NULL DEFAULT '',
PRIMARY KEY (`tag_id`),
UNIQUE KEY `title` (`title`)
)ENGINE=MyISAM
AUTO_INCREMENT=1 CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
CREATE TABLE `tag_relations` (
`article_id` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',
`tag_id` MEDIUMINT(9) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`article_id`, `tag_id`)
)ENGINE=InnoDB
ROW_FORMAT=FIXED CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
All articles have some tags and I want to make a relation between articles by tags. I want to make the most matching articles (limiting the article count with 5-6 maybe) be displayed.
Ex; if "Article-1" has 4 tags like "tag-1, tag-2, tag-3, tag-4"; I want to display other articles that have all those tags too. If there are no matching articles, than 3-matching-tags articles would be displayed. If there are no 3-matching-tags, than it would be 2 and at last 1-matching-tag. And I want to display articles that are in the same category.
I've found some SQL examples but none worked like I want. If anyone can help, I'd be very pleased.
Thanks.