Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-01-2015, 07:42 PM
SilverBoy SilverBoy is offline
 
Join Date: Feb 2002
Location: Libya
Posts: 497
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Related articles [CMS]

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.
Reply With Quote
  #2  
Old 04-02-2015, 10:11 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 04-03-2015, 03:14 AM
SilverBoy SilverBoy is offline
 
Join Date: Feb 2002
Location: Libya
Posts: 497
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 [DATE]1428120755[/DATE] at [TIME]1428120755[/TIME] ---------------

Any ideas?

By the way here is the function that do the most work of similar threads
PHP Code:
    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_fulltext')) ? 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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:12 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03642 seconds
  • Memory Usage 2,204KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (3)post_thanks_box
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit_info
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete