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;
////////////////////////////////////
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...