punbb/include/search_idx.php
changeset 2 a8a21e1c7afa
parent 0 f9ffdbd96607
--- a/punbb/include/search_idx.php	Wed Jul 11 21:28:39 2007 -0400
+++ b/punbb/include/search_idx.php	Thu Jul 12 01:04:01 2007 -0400
@@ -86,7 +86,7 @@
 //
 function update_search_index($mode, $post_id, $message, $subject = null)
 {
-	global $db_type, $db;
+	global $db_type, $pun_db;
 
 	// Split old and new post/subject to obtain array of 'words'
 	$words_message = split_words($message);
@@ -94,19 +94,19 @@
 
 	if ($mode == 'edit')
 	{
-		$result = $db->query('SELECT w.id, w.word, m.subject_match FROM '.$db->prefix.'search_words AS w INNER JOIN '.$db->prefix.'search_matches AS m ON w.id=m.word_id WHERE m.post_id='.$post_id, true) or error('Unable to fetch search index words', __FILE__, __LINE__, $db->error());
+		$result = $pun_db->query('SELECT w.id, w.word, m.subject_match FROM '.$pun_db->prefix.'search_words AS w INNER JOIN '.$pun_db->prefix.'search_matches AS m ON w.id=m.word_id WHERE m.post_id='.$post_id, true) or error('Unable to fetch search index words', __FILE__, __LINE__, $pun_db->error());
 
 		// Declare here to stop array_keys() and array_diff() from complaining if not set
 		$cur_words['post'] = array();
 		$cur_words['subject'] = array();
 
-		while ($row = $db->fetch_row($result))
+		while ($row = $pun_db->fetch_row($result))
 		{
 			$match_in = ($row[2]) ? 'subject' : 'post';
 			$cur_words[$match_in][$row[1]] = $row[0];
 		}
 
-		$db->free_result($result);
+		$pun_db->free_result($result);
 
 		$words['add']['post'] = array_diff($words_message, array_keys($cur_words['post']));
 		$words['add']['subject'] = array_diff($words_subject, array_keys($cur_words['subject']));
@@ -120,7 +120,7 @@
 		$words['del']['post'] = array();
 		$words['del']['subject'] = array();
 	}
-
+  
 	unset($words_message);
 	unset($words_subject);
 
@@ -129,36 +129,36 @@
 
 	if (!empty($unique_words))
 	{
-		$result = $db->query('SELECT id, word FROM '.$db->prefix.'search_words WHERE word IN('.implode(',', preg_replace('#^(.*)$#', '\'\1\'', $unique_words)).')', true) or error('Unable to fetch search index words', __FILE__, __LINE__, $db->error());
-
+		$result = $pun_db->query('SELECT id, word FROM '.$pun_db->prefix.'search_words WHERE word IN('.implode(',', preg_replace('#^(.*)$#', '\'\1\'', $unique_words)).')', true) or error('Unable to fetch search index words', __FILE__, __LINE__, $pun_db->error());
+    
 		$word_ids = array();
-		while ($row = $db->fetch_row($result))
+		while ($row = $pun_db->fetch_row($result))
 			$word_ids[$row[1]] = $row[0];
-
-		$db->free_result($result);
-
+    
+		$pun_db->free_result($result);
+    
 		$new_words = array_diff($unique_words, array_keys($word_ids));
 		unset($unique_words);
-
+    
 		if (!empty($new_words))
 		{
 			switch ($db_type)
 			{
 				case 'mysql':
 				case 'mysqli':
-					$db->query('INSERT INTO '.$db->prefix.'search_words (word) VALUES'.implode(',', preg_replace('#^(.*)$#', '(\'\1\')', $new_words))) or error('Unable to insert search index words', __FILE__, __LINE__, $db->error());
+					$pun_db->query('INSERT INTO '.$pun_db->prefix.'search_words (word) VALUES'.implode(',', preg_replace('#^(.*)$#', '(\'\1\')', $new_words))) or error('Unable to insert search index words', __FILE__, __LINE__, $pun_db->error());
 					break;
 
 				default:
 					while (list(, $word) = @each($new_words))
-						$db->query('INSERT INTO '.$db->prefix.'search_words (word) VALUES(\''.$word.'\')') or error('Unable to insert search index words', __FILE__, __LINE__, $db->error());
+						$pun_db->query('INSERT INTO '.$pun_db->prefix.'search_words (word) VALUES(\''.$word.'\')') or error('Unable to insert search index words', __FILE__, __LINE__, $pun_db->error());
 					break;
 			}
 		}
 
 		unset($new_words);
 	}
-
+  
 	// Delete matches (only if editing a post)
 	while (list($match_in, $wordlist) = @each($words['del']))
 	{
@@ -170,7 +170,7 @@
 			while (list(, $word) = @each($wordlist))
 				$sql .= (($sql != '') ? ',' : '').$cur_words[$match_in][$word];
 
-			$db->query('DELETE FROM '.$db->prefix.'search_matches WHERE word_id IN('.$sql.') AND post_id='.$post_id.' AND subject_match='.$subject_match) or error('Unable to delete search index word matches', __FILE__, __LINE__, $db->error());
+			$pun_db->query('DELETE FROM '.$pun_db->prefix.'search_matches WHERE word_id IN('.$sql.') AND post_id='.$post_id.' AND subject_match='.$subject_match) or error('Unable to delete search index word matches', __FILE__, __LINE__, $pun_db->error());
 		}
 	}
 
@@ -180,7 +180,7 @@
 		$subject_match = ($match_in == 'subject') ? 1 : 0;
 
 		if (!empty($wordlist))
-			$db->query('INSERT INTO '.$db->prefix.'search_matches (post_id, word_id, subject_match) SELECT '.$post_id.', id, '.$subject_match.' FROM '.$db->prefix.'search_words WHERE word IN('.implode(',', preg_replace('#^(.*)$#', '\'\1\'', $wordlist)).')') or error('Unable to insert search index word matches', __FILE__, __LINE__, $db->error());
+			$pun_db->query('INSERT INTO '.$pun_db->prefix.'search_matches (post_id, word_id, subject_match) SELECT '.$post_id.', id, '.$subject_match.' FROM '.$pun_db->prefix.'search_words WHERE word IN('.implode(',', preg_replace('#^(.*)$#', '\'\1\'', $wordlist)).')') or error('Unable to insert search index word matches', __FILE__, __LINE__, $pun_db->error());
 	}
 
 	unset($words);
@@ -192,30 +192,30 @@
 //
 function strip_search_index($post_ids)
 {
-	global $db_type, $db;
+	global $db_type, $pun_db;
 
 	switch ($db_type)
 	{
 		case 'mysql':
 		case 'mysqli':
 		{
-			$result = $db->query('SELECT word_id FROM '.$db->prefix.'search_matches WHERE post_id IN('.$post_ids.') GROUP BY word_id') or error('Unable to fetch search index word match', __FILE__, __LINE__, $db->error());
+			$result = $pun_db->query('SELECT word_id FROM '.$pun_db->prefix.'search_matches WHERE post_id IN('.$post_ids.') GROUP BY word_id') or error('Unable to fetch search index word match', __FILE__, __LINE__, $pun_db->error());
 
-			if ($db->num_rows($result))
+			if ($pun_db->num_rows($result))
 			{
 				$word_ids = '';
-				while ($row = $db->fetch_row($result))
+				while ($row = $pun_db->fetch_row($result))
 					$word_ids .= ($word_ids != '') ? ','.$row[0] : $row[0];
 
-				$result = $db->query('SELECT word_id FROM '.$db->prefix.'search_matches WHERE word_id IN('.$word_ids.') GROUP BY word_id HAVING COUNT(word_id)=1') or error('Unable to fetch search index word match', __FILE__, __LINE__, $db->error());
+				$result = $pun_db->query('SELECT word_id FROM '.$pun_db->prefix.'search_matches WHERE word_id IN('.$word_ids.') GROUP BY word_id HAVING COUNT(word_id)=1') or error('Unable to fetch search index word match', __FILE__, __LINE__, $pun_db->error());
 
-				if ($db->num_rows($result))
+				if ($pun_db->num_rows($result))
 				{
 					$word_ids = '';
-					while ($row = $db->fetch_row($result))
+					while ($row = $pun_db->fetch_row($result))
 						$word_ids .= ($word_ids != '') ? ','.$row[0] : $row[0];
 
-					$db->query('DELETE FROM '.$db->prefix.'search_words WHERE id IN('.$word_ids.')') or error('Unable to delete search index word', __FILE__, __LINE__, $db->error());
+					$pun_db->query('DELETE FROM '.$pun_db->prefix.'search_words WHERE id IN('.$word_ids.')') or error('Unable to delete search index word', __FILE__, __LINE__, $pun_db->error());
 				}
 			}
 
@@ -223,9 +223,9 @@
 		}
 
 		default:
-			$db->query('DELETE FROM '.$db->prefix.'search_words WHERE id IN(SELECT word_id FROM '.$db->prefix.'search_matches WHERE word_id IN(SELECT word_id FROM '.$db->prefix.'search_matches WHERE post_id IN('.$post_ids.') GROUP BY word_id) GROUP BY word_id HAVING COUNT(word_id)=1)') or error('Unable to delete from search index', __FILE__, __LINE__, $db->error());
+			$pun_db->query('DELETE FROM '.$pun_db->prefix.'search_words WHERE id IN(SELECT word_id FROM '.$pun_db->prefix.'search_matches WHERE word_id IN(SELECT word_id FROM '.$pun_db->prefix.'search_matches WHERE post_id IN('.$post_ids.') GROUP BY word_id) GROUP BY word_id HAVING COUNT(word_id)=1)') or error('Unable to delete from search index', __FILE__, __LINE__, $pun_db->error());
 			break;
 	}
 
-	$db->query('DELETE FROM '.$db->prefix.'search_matches WHERE post_id IN('.$post_ids.')') or error('Unable to delete search index word match', __FILE__, __LINE__, $db->error());
+	$pun_db->query('DELETE FROM '.$pun_db->prefix.'search_matches WHERE post_id IN('.$post_ids.')') or error('Unable to delete search index word match', __FILE__, __LINE__, $pun_db->error());
 }