Public feed
#532277
<?php
include("../include/session.php");
function populateKeywords(){
$time = microtime();
$f = array('\\', '\'','\"','.',',','!','?',':','(',')','*'); //set array of characters to replace
$r = array('\\\\', '\\\'','\\\"','','','','','','','',''); //set array of characters to replace with
$query = mysql_query("select aid,title,summary,body from articles"); //query for aid,title,summary,body
while($article = mysql_fetch_array($query)){ //$article
$exists = FALSE; //set duplicate word exist to false
$words = array(); //create word array
$words = explode(" ",$article['title']); //add all words from the article title
$words .= explode(" ",$article['summary']); //add all words from the article summary
$words .= explode(" ",$article['body']); //add all words from the article body
for($i=0;$i<count($words);$i++){ //iterate through the words
if(strlen($words[$i])>3){ //if the length of word $i is great than 3, continue
$word = strtolower($words[$i]); //set $word to lowercase
$word = str_replace($f,$r,$word); //replace $f with $r
$query2 = mysql_query("select word from searchWords where articleIds=".(int)$article['aid']); //query for word(s)
while($word_check = mysql_fetch_array($query2)){ //iterate through all indexed words
if(strcmp($word_check['word'],$word)==0){ //if indexed word is equal to the currently selected word
$exists = TRUE; //set duplicate exists to TRUE
} //end if
} //end while
if(!$exists){ //check if exists is TRUE
mysql_query("INSERT INTO searchWords VALUES (0, '".$word."',".(int)$article['aid'].")") or die(mysql_error()); //insert new word,aid into table
}
} //end check if exists
} //end for loop
unset($words);
unset($article);
}
print "Successful!";
print microtime() - $time;
}
populateKeywords();
?>