PDA

View Full Version : Related articles [CMS]


SilverBoy
04-01-2015, 07:42 PM
Hi

I'm trying to implement new widget to display related articles to the current one which user read. my principle built on using "Tags" as a key to find best results.

The problem is that when I tried to write the algorithm for the widget code, I had bad feeling and I think it is not the right way to do this thing and if it works it will be hungry resources widget.

My algorithm works like this, first catch all tags the article has, then search on them on other articles, if the tag1 found in article1 then there is a new special field stored in the nodes DB with default value '0' will be '1'.

after that I will check articles for Tag2, and if article2 have it the new field will be '1', and if article1 has it too the value of the field will be '2', and so on for the rest of tags.

Then we will sort the articles regarding to 2 factors, 1 is the value of the new field (desc. sort) and 2 is the date and time of publishing date-time and select only articles which have been written before the time-date of publishing of the current article and order of the list will be desc to (to show near written articles first).

The result will show the most relevant articles and most near articles in the widget.

After completing the work the value of the new field will be reset to '0' again.

Any help to implement this widget?

Thanks in advance.

kh99
04-02-2015, 10:11 AM
I'm not sure I follow that completely, but I think what you're saying is that you want to find articles with the most tags in common. You say you only want articles that were written before the current one, but why not show articles written after as well? But maybe you have a reason for that.

Anyway, the way "similar threads" works is that it finds the similar threads then stores a field in the thread table that is a comma separated list of threadids, so that it doesn't do the work of locating the similar threads every time it needs to display them.

SilverBoy
04-03-2015, 03:14 AM
Thank you kh99 for your reply.

Yes I want articles with most tags in common, and yes I have a reason for choosing only display articles that published before the one that user read it in that time, and the reason so simple and logically, I used the CMS as news platform on my site, and with this feature I can make stories linked to each other and I can let users stays more time in my site by traveling form one article to another to understand the story exactly and clearly, but if I display the articles published after the one the user is reading the chain of articles will be broken and the misunderstand may be happened, even that I have another reason (Technically one) if I will show new articles too, that means I have to run the check for that article every time new article published in my site, but the logic said I have to do this only when add article or edit it (including add and delete tags).

Any way, I still waiting for someone to help me to make this feature available :)

Thanks.

--------------- Added 1428120755 at 1428120755 ---------------

Any ideas?

By the way here is the function that do the most work of similar threads
public function get_similar_threads($threadtitle, $threadid = 0)
{
global $vbulletin;

//we'll leave the join stuff in from the existing hook, though its
//likely to break any existing code because we've changed the query
$hook_query_joins = $hook_query_where = '';
$similarthreads = null;
($hook = vBulletinHook::fetch_hook('search_similarthreads_f ulltext')) ? eval($hook) : false;

if ($similarthreads !== null)
{
return $similarthreads;
}

$contenttypeid = vB_Types::instance()->getContentTypeID('vBForum_Thread');

$safetitle = $vbulletin->db->escape_string($threadtitle);
$threads = $vbulletin->db->query_read_slave("
SELECT searchgroup.groupid, MATCH(searchgroup_text.title) AGAINST ('$safetitle') AS score
FROM " . TABLE_PREFIX . "searchgroup AS searchgroup JOIN " . TABLE_PREFIX . "searchgroup_text AS searchgroup_text ON
(searchgroup.searchgroupid = searchgroup_text.searchgroupid)
$hook_query_joins
WHERE MATCH(searchgroup_text.title) AGAINST ('$safetitle') AND
searchgroup.contenttypeid = $contenttypeid
" . ($threadid ? " AND searchgroup.groupid <> $threadid" : "") . "
$hook_query_where
HAVING score > 4
LIMIT 5
");

$similarthreads = array();
while ($thread = $vbulletin->db->fetch_array($threads))
{
$similarthreads[] = $thread['groupid'];
}
$vbulletin->db->free_result($threads);
return $similarthreads;
}

But the problem here is that I have x tags for every single article, so I don't get the best way to write the code without a lot of loops.

I wish some one can help in this.

Thanks in advance.