Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-03-2002, 04:18 AM
DarkReaper DarkReaper is offline
 
Join Date: Oct 2001
Posts: 429
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Using indexpost() on non-vB Pages...

I'm writing a news system that inserts news into vBulletin for comments, and am having trouble getting the posts to be indexed for searching. I'm not including any vB files, so I copied the indexpost() function over and had it switch databases to the forums DB to index it. However, it's not indexing the posts...

PHP Code:
// ###################### Start indexpost #######################
function indexpost($postid) {
  global 
$DB_site;
  
$minsearchlength 3;
  
$maxsearchlength 18;

  echo 
"val = $val<br>";


  
$DB_site->select_db($forumdbname);


  
$post=$DB_site->query_first("SELECT postid,threadid,title,pagetext FROM post WHERE postid='$postid'");


    
$threadinfo=$DB_site->query_first("SELECT title FROM thread WHERE threadid=$post[threadid]");
    
//$post[title].=" ".$threadinfo[title];

    // What is the point of this?///////
    
$firstpst[$post[threadid]]=$postid;
    
////////////////////////////////////

    
$titlewords=trim($threadinfo[title]);
    
$titlewords=ereg_replace("[\n\t\r,]"," ",$titlewords);
     
$titlewords=preg_replace("/(\.+)($| |\n|\t)/s"" "$titlewords);
     
$titlewords=str_replace("["" ["$titlewords);
     
$titlewords=str_replace("]""] "$titlewords);
     
$titlewords=preg_replace("/[\(\)\"':;\[\]?!#{}_\-+\\\\]/s","",$titlewords);
     
$titlewords=strtolower(trim(str_replace("  "," ",$titlewords)));
     
$titlewordarray=explode(" ",$titlewords);
     while (list(
$key,$val)=each($titlewordarray)) {
         echo 
"val = $val<br>";
       
$titlearray[$val]=1;
     }


  
$allwords=$post[title]." ".$post[pagetext];
  
$allwords=preg_replace("/[\n\t\r,]/s"," ",$allwords);
  
$allwords=preg_replace("/(\.+)($| |\n|\t)/s"" "$allwords);
  
$allwords=str_replace("["" ["$allwords);
  
$allwords=str_replace("]""] "$allwords);
  
$allwords=preg_replace("/[\(\)\"':;\[\]?!#{}_\-+\\\\]/s","",$allwords);
  
$allwords=strtolower(trim(str_replace("  "," ",$allwords)));
  if (
$titlewords)
    
$allwords.=" ".$titlewords;
  
$wordarray=explode(" ",$allwords);


  
$getwordidsql="title IN ('".str_replace(" ","','",$allwords)."')";
  
$words=$DB_site->query("SELECT wordid,title FROM word WHERE $getwordidsql");

  while (
$word=$DB_site->fetch_array($words)) {
    
$wordcache[$word[title]]=$word[wordid];
  }
  
$DB_site->free_result($words);

  
$insertsql="";
  
$newwords="";

  echo 
"val = $val<br>";
  echo 
"worddone[val] = $worddone[$val]<br>";

    if (
$val!=""  and !$worddone[$val]) {
      
$worddone[$val]=1// Ok we have added this word
      
if (isset($wordcache[$val])) { // Does this word already exist in the word table?
        
if (isset($titlearray[$val]))
          
$intitle=1;
        else
          
$intitle=0;
        
$insertsql.=",($wordcache[$val],$postid,$intitle)"// yes so just add a searchindex entry for this post/word
        
echo "insertsql is now $insertsql<br>";
        
flush();
      } else {
        if (isset(
$titlearray[$val]))
        {
          
$newtitlewords.=$val." ";
          echo 
"Added $val to the title table<br>";
          
flush();
        }
        else
        {
          
$newwords.=$val." "// No so add it to the word table
          
echo "Added $val to the word table<br>";
          
flush();
        }
      }
    }


  

  if (
$insertsql!="") {
    
$insertsql=substr($insertsql,1);
    
$DB_site->query("REPLACE INTO searchindex (wordid,postid,intitle) VALUES $insertsql");
  }

  if (
$newwords) {
    
$newwords=trim($newwords);
    
$insertwords="(NULL,'".str_replace(" ","'),(NULL,'",addslashes($newwords))."')";
    
$DB_site->query("INSERT IGNORE INTO word (wordid,title) VALUES $insertwords");
    
$selectwords="title IN('".str_replace(" ","','",addslashes($newwords))."')";
    
$DB_site->query("INSERT IGNORE INTO searchindex (wordid,postid) SELECT DISTINCT wordid,$postid FROM word WHERE $selectwords");
   }

   if (
$newtitlewords) {
     
$newtitlewords=trim($newtitlewords);
     
$insertwords="(NULL,'".str_replace(" ","'),(NULL,'",addslashes($newtitlewords))."')";
     
$DB_site->query("INSERT IGNORE INTO word (wordid,title) VALUES $insertwords");
     
$selectwords="title IN('".str_replace(" ","','",addslashes($newtitlewords))."')";
     
$DB_site->query("REPLACE INTO searchindex (wordid,postid,intitle) SELECT DISTINCT wordid,$postid,1 FROM word WHERE $selectwords");
   }

   
$DB_site->select_db($dbname);

What am I doing wrong?

Edit: Oh, btw..the echos were there to help me debug..didn't work very well...$val was empty on those echos, except for in the loop...$worddone[$val] was always empty...
Reply With Quote
  #2  
Old 06-03-2002, 10:53 AM
Logician's Avatar
Logician Logician is offline
 
Join Date: Nov 2001
Location: inside vb code
Posts: 4,449
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Either I didnt understand what exactly you are trying to do or you are inserting into wrong tables: Why arent you inserting your posts into "thread" and "post" tables if you are trying to add them into your vb db as messages?
Reply With Quote
  #3  
Old 06-03-2002, 12:48 PM
DarkReaper DarkReaper is offline
 
Join Date: Oct 2001
Posts: 429
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am. I insert them to the post and thread table and then try to index them via that function. It doesn't work.
Reply With Quote
  #4  
Old 06-03-2002, 01:25 PM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Require global.php and then call indexpost(), you'll have to completely rewrite the function otherwise.
Reply With Quote
  #5  
Old 06-03-2002, 01:30 PM
DarkReaper DarkReaper is offline
 
Join Date: Oct 2001
Posts: 429
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think including global.php would cause problems though..I'm using a different DB than the forums one, and am using a variable named $DB_site to access it...
Reply With Quote
  #6  
Old 06-03-2002, 01:32 PM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So you have $DB_site already defined? Should've said so.

What's the problem then? Is the $DB_site class identical to the one vBulletin uses?
Reply With Quote
  #7  
Old 06-03-2002, 01:36 PM
DarkReaper DarkReaper is offline
 
Join Date: Oct 2001
Posts: 429
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm using the exact same $DB_site class, but with a different DB in completely separate files.
Reply With Quote
  #8  
Old 06-03-2002, 01:40 PM
Logician's Avatar
Logician Logician is offline
 
Join Date: Nov 2001
Location: inside vb code
Posts: 4,449
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by DarkReaper
I am. I insert them to the post and thread table and then try to index them via that function. It doesn't work.
If you are already inserting into post and thread table, what's the point of your custom "indexing"? Post table has default indexing via MYSQL and your threads are already supposed to be found via Search.
Reply With Quote
  #9  
Old 06-03-2002, 01:44 PM
DarkReaper DarkReaper is offline
 
Join Date: Oct 2001
Posts: 429
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm inserting the thread and post manually, therefore I also have to index it or it will not show up in search.
Reply With Quote
  #10  
Old 06-03-2002, 01:50 PM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by Logician
If you are already inserting into post and thread table, what's the point of your custom "indexing"? Post table has default indexing via MYSQL and your threads are already supposed to be found via Search.
MySQL indexing <> vBulletin indexing. The latter is used for searches, if you don't index your posts they will not show up when you search.
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 10:59 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04326 seconds
  • Memory Usage 2,308KB
  • Queries Executed 11 (?)
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
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete