PDA

View Full Version : Using indexpost() on non-vB Pages...


DarkReaper
06-03-2002, 04:18 AM
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...


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

Logician
06-03-2002, 10:53 AM
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?

DarkReaper
06-03-2002, 12:48 PM
I am. I insert them to the post and thread table and then try to index them via that function. It doesn't work.

Admin
06-03-2002, 01:25 PM
Require global.php and then call indexpost(), you'll have to completely rewrite the function otherwise.

DarkReaper
06-03-2002, 01:30 PM
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...

Admin
06-03-2002, 01:32 PM
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?

DarkReaper
06-03-2002, 01:36 PM
I'm using the exact same $DB_site class, but with a different DB in completely separate files.

Logician
06-03-2002, 01:40 PM
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.

DarkReaper
06-03-2002, 01:44 PM
I'm inserting the thread and post manually, therefore I also have to index it or it will not show up in search.

Admin
06-03-2002, 01:50 PM
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.

DarkReaper
06-03-2002, 01:52 PM
Well..now that we have that cleared up, how can I do this? :)

Admin
06-03-2002, 02:11 PM
Originally posted by FireFly
What's the problem then?

DarkReaper
06-03-2002, 02:24 PM
Originally posted by DarkReaper
I'm using the exact same $DB_site class, but with a different DB in completely separate files.

Therefore I can't include vB's global.php file to use it's indexpost() function...

Admin
06-03-2002, 02:51 PM
What's the problem... errors, warning, anything? What doesn't work?

DarkReaper
06-03-2002, 09:26 PM
I got an error in /forums/global.php when it tried to include /admin/config.php. Also, I'd suspect that it wouldn't work anyway because of the two $DB_site variables...

DarkReaper
06-04-2002, 04:59 PM
...

DarkReaper
06-05-2002, 05:37 PM
....

Admin
06-06-2002, 08:27 AM
How about helping me help you? What is the error??

DarkReaper
06-22-2002, 06:30 PM
I thought I posted this, but the email reply thing just now told me it errored.


Warning: Unable to access ./admin/config.php in
/home/virtual/site19/fst/var/www/html/forums/global.php on line 117

I'd also suspect that it'll error because of two instances of $DB_site

Admin
06-23-2002, 05:57 AM
It can't find config.php, make sure you use the right path.

DarkReaper
06-25-2002, 05:15 AM
I used the right path for including the forums' global.php