ProcessForm Function():
The code is similar to Part 1 coding, only here the occurrence count is added in link table along
with key id an content id. Here is the code.
with key id an content id. Here is the code.
<?php
while(list($word,$occurances)=each($wordList)){
$keyId = "";
if ( !$allWords[$word] ) {
mysql_query( sprintf( "INSERT INTO keytable ( keyword ) VALUES ( '%s' )",
mysql_escape_string($word) ) );
$keyId = mysql_insert_id();
$allWords[$word] = $keyId;
}
else {
$keyId = $allWords[$word];
}
// insert the link
mysql_query( sprintf( "INSERT INTO link (keyid, contid, occurrences)
VALUES ( %d, %d, %d)",
$keyId, $contentId,$occurances ) );
}
?>
Search Engine:
As discussed in the Introduction part, here the search is performed with number of occurrences
in each document. Here is the code.
in each document. Here is the code.
<?php
while($lRow=mysql_fetch_array($lResult)){
$thisContentId=$lRow["contid"];
if(!$contArray[$thisContentId]){
$contArray[$thisContentId]["oc"]=$lRow["occurances"];
$contArray[$thisContentId]["id"]=$lRow["contid"];
$contArray[$thisContentId]["wrank"]=1;
}else{
$contArray[$thisContentId]["oc"]+=$lRow["occurances"];
$contArray[$thisContentId]["wrank"]++;
}
}
?>