Public feed #532216

Something

public text v1 · immutable
Raw Edit
·published 2007-06-03 02:53 UTC
rendered paste body
<?php
include("../include/session.php");

function populateKeywords(){
		$time = microtime();
		$f = array('\\', '\'','\"','.',',','!','?',':','(',')','*');
		$r = array('\\\\', '\\\'','\\\"','','','','','','','','');
	$query = mysql_query("select aid,title,summary,body from articles");
	while($article = mysql_fetch_array($query)){
		$exists = FALSE;
		$words = array();
		$words = explode(" ",$article['title']);
		$words += explode(" ",$article['summary']);
		$words += explode(" ",$article['body']);
		for($i=0;$i<count($words);$i++){ //start for loop
			if(strlen($words[$i])>3){
			$word = strtolower($words[$i]);
			$words = str_replace($f,$r,$words);
				$query2 = mysql_query("select word from searchWords where articleIds=".(int)$article['aid']);
				while($word_check = mysql_fetch_array($query2)){ //start while loop
					if($word_check['word']==$word){
						$exists = TRUE;
					} //end check duplicates
				} //end while loop
				if(!$exists){ //check if exists
					mysql_query("INSERT INTO searchWords VALUES (0, '".$word."',".(int)$article['aid'].")") or die(mysql_error());
				}
			} //end check if exists
		} //end for loop
		unset($words);
		unset($article);
	}
	print "Successful!";
	print microtime() - $time;
}

populateKeywords();
?>