#native_company# #native_desc#
#native_cta#

Dynamic Document Search Engine – Part 2 Page 3

By M.Murali Dharan
on February 25, 2004

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.

<?php

while(list($word,$occurances)=each($wordList)){

        
$keyId "";

        if ( !
$allWords[$word] ) {

            
mysql_querysprintf"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_querysprintf"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.

<?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"]++;

        }

}

?>