Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > General > Member Archives
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Related topics for non-vB pages Details »»
Related topics for non-vB pages
Version: , by ScottA ScottA is offline
Developer Last Online: Dec 2006 Show Printable Version Email this Page

Version: Unknown Rating:
Released: 10-15-2002 Last Update: Never Installs: 0
 
No support by the author.

This isn't really a hack, more of an add-on for vBulletin.

What I'm trying to do is create a method of displaying related topics at the end of articles for NissanPerformanceMag.com. This isn't the same as the "Last XX Posts on non-vB page" hack. Instead, it uses some specified keywords to display 10 discussion topics related to the subject of the article. I haven't been able to locate any similar projects, so I attempted it myself.

It's easy to get lost in the search.php file (at least for me ), but I was able to figure out enough to get this far. It displays the queries used, as well as the final results. The problem is it doesn't work very well with multiple words, such as this:

I can't figure out how to make it display threads containing all of the search words. Right now it uses "OR" instead of "AND", if you can see what I mean. It also doesn't give any weight to results. If anyone can offer some insight into methods of improving this I would appreciate it very much! What I would like to do (using the second link as an example), is display threads containing all the search words instead of simply displaying threads that contain just one.

Here's the code:

PHP Code:
<?php
mysql_connect
("localhost""username""password");
$words strtolower($_GET['query']);
$words explode(' '$words);
for (
$i 0$i count($words); $i++) {
  
$searchwords .= "title = '{$words[$i]}'";
  if (
$icount($words)) {
    
$searchwords .= ' OR ';
  }
}
$query "SELECT wordid FROM word WHERE $searchwords";
echo 
"<p>$query";
unset(
$searchwords);
$result mysql_db_query("forums"$query);
if (
mysql_num_rows($result) >= 1) {
  
$i 1;
  while (
$r mysql_fetch_array($result)) {
    if (
$i 1) {
      
$searchwords .= ', ';
    }
    
$searchwords .= "'{$r['wordid']}'";
    
$i++;
  }
  
$query "SELECT DISTINCT postid FROM searchindex WHERE wordid IN($searchwords)";
  echo 
"<p>$query";
  unset(
$searchwords);
  
$result mysql_db_query("forums"$query);
  
$i 1;
  while (
$r mysql_fetch_array($result)) {
    if (
$i 1) {
      
$searchwords .= ', ';
    }
    
$searchwords .= "'{$r['postid']}'";
    
$i++;
  }
  
$query "SELECT threadid FROM post WHERE postid IN($searchwords) ORDER BY dateline DESC";
  echo 
"<p>$query";
  unset(
$searchwords);
  
$result mysql_db_query("forums"$query);
  
$i 1;
  while (
$r mysql_fetch_array($result)) {
    if (
$i 1) {
      
$searchwords .= ', ';
    }
    
$searchwords .= "'{$r['threadid']}'";
    
$i++;
  }
  
$query "SELECT threadid, title, replycount, views FROM thread 
  WHERE threadid IN(
$searchwords) ORDER BY lastpost DESC LIMIT 10";
echo 
"<p>$query";
  
$result mysql_db_query("forums"$query);
  while (
$r mysql_fetch_array($result)) {
    echo 
"<p><a href=\"http://www.nissanforums.com/showthread.php?threadid={$r['threadid']}\">{$r['title']}</a>";
  }
}
mysql_close();
?>

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #2  
Old 10-16-2002, 08:42 PM
ScottA ScottA is offline
 
Join Date: May 2002
Posts: 12
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, I did eventually figure out the problem. It just involved rewriting a couple of the queries. I removed the link from the previous post because I've since deleted the file.
Reply With Quote
  #3  
Old 10-17-2002, 09:53 PM
SteveK SteveK is offline
 
Join Date: Oct 2001
Location: Seattle, WA USA
Posts: 41
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This sounds like what I'd like to implement. Can you share with us the final hack?

Thanks

Steve
Reply With Quote
  #4  
Old 10-17-2002, 10:19 PM
ScottA ScottA is offline
 
Join Date: May 2002
Posts: 12
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sure. Here's what I came up with. The only real differences between my first attempt and this final version are the third and fourth MySQL queries. It does not return the most recent results. What it does instead is group the threads with the highest number of instances of the search word(s), and then sort those by date. It may not be the most efficient or desirable system for your particular application, but it seems to work pretty well. If you come up with any improvements please let me know.

I've simply included it as a function, which can be called with some keywords separated by spaces. I'd recommend not using more than 2 or 3 keywords simply because of the large number of posts it will find. If you print out the queries like I did in my first example you'll see just how many! Change "LIMIT 5" to the number of results you want.

PHP Code:
related_threads("keyword1 keyword2 etc"); 
Related Threads:

PHP Code:
<?php
function related_threads($keywords) {
  @
mysql_connect("localhost""username""password");
  
$words strtolower($keywords);
  
$words explode(' '$words);
  for (
$i 0$i count($words); $i++) {
    
$searchwords .= "title = '{$words[$i]}'";
    if (
$icount($words)) {
      
$searchwords .= ' OR ';
    }
  }
  
$query "SELECT wordid FROM word WHERE $searchwords";
  unset(
$searchwords);
  
$result = @mysql_db_query("forums"$query);
  if (@
mysql_num_rows($result) >= 1) {
    
$i 1;
    while (
$r = @mysql_fetch_array($result)) {
      if (
$i 1) {
        
$searchwords .= ', ';
      }
      
$searchwords .= "'{$r['wordid']}'";
      
$i++;
    }
    
$query "SELECT DISTINCT postid FROM searchindex WHERE wordid IN($searchwords)";
    unset(
$searchwords);
    
$result = @mysql_db_query("forums"$query);
    
$i 1;
    while (
$r = @mysql_fetch_array($result)) {
      if (
$i 1) {
        
$searchwords .= ', ';
      }
      
$searchwords .= "'{$r['postid']}'";
      
$i++;
    }
    
$query "SELECT threadid, count(threadid) AS count FROM post WHERE postid IN($searchwords) AND visible = '1' 
GROUP BY threadid ORDER BY count DESC, dateline LIMIT 5"
;
    unset(
$searchwords);
    
$result = @mysql_db_query("forums"$query);
    
$i 1;
    while (
$r = @mysql_fetch_array($result)) {
      if (
$i 1) {
        
$searchwords .= ', ';
      }
      
$searchwords .= "'{$r['threadid']}'";
      
$i++;
    }
    
$query "SELECT threadid, title, replycount, dateline FROM thread WHERE threadid IN($searchwords) AND visible 
= '1' AND open = '1' ORDER BY lastpost DESC"
;
    
$result = @mysql_db_query("forums"$query);
    echo 
"<table border=\"1\" cellpadding=\"5\" cellspacing=\"0\" width=\"100%\">\n  <tr>\n    <td>Thread</td>\n    
<td>Date</td>\n    <td>Replies</td>\n  </tr>\n"
;
    while (
$r = @mysql_fetch_array($result)) {
      echo 
"  <tr>\n    <td><a href=\"http://www.nissanforums.com/showthread.php?threadid={$r['threadid']}\" 
target=\"_blank\">
{$r['title']}</a></td>\n    <td>" date("m-d-y"$r['dateline']) . "</td>\n    <td>{$r['replycount']}
</td>\n  </tr>\n"
;
    }
    echo
"</table>\n";
  }
  @
mysql_close();
}
?>
Edit: I wrapped some of the lines so they'd fit on my screen...

Scott
Reply With Quote
  #5  
Old 10-18-2002, 01:02 AM
DrkFusion's Avatar
DrkFusion DrkFusion is offline
 
Join Date: Nov 2001
Posts: 1,926
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hey nice mag, how can I subscribe :O)
-Arunan
Reply With Quote
  #6  
Old 10-18-2002, 11:06 AM
ScottA ScottA is offline
 
Join Date: May 2002
Posts: 12
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It's online only at this time. Eventually we want to have it in print, but we're not there yet.
Reply With Quote
  #7  
Old 01-07-2003, 07:13 PM
mt_100 mt_100 is offline
 
Join Date: Mar 2002
Posts: 29
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

How are you calling the function from the search form? I can't seem to get it right, can I have a copy of your search form?
Reply With Quote
  #8  
Old 01-07-2003, 09:49 PM
ScottA ScottA is offline
 
Join Date: May 2002
Posts: 12
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

A search form is not required. Call the function from within your PHP file with some words and it outputs the appropriate HTML. This isn't intended to be used as a search program, but rather a method of displaying related forum topics at the end of articles for NissanPerformanceMag.com. The example I gave above is exactly how it's used for my own situation. I just change the search words as appropriate.
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 02:37 PM.


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.04366 seconds
  • Memory Usage 2,326KB
  • Queries Executed 21 (?)
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
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (7)postbit
  • (8)postbit_onlinestatus
  • (8)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_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