PHPBuilder - Dynamic Document Search Engine - Part 2 Page 3



RSS Twitter
Articles Tricks And Hacks

Dynamic Document Search Engine - Part 2 - Page 3

by: M.Murali Dharan
|
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"]++;
        }
}
?>

« Previous Page
1
|
2
|
3
|
4
|
5
|
6
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
M.Murali Dharan

Comment:



Comment:

(Maximum characters: 1200). You have characters left.