#native_company# #native_desc#
#native_cta#

Dynamic Document Search Engine – Part 1 Page 8

By M.Murali Dharan
on February 17, 2004

Search Engine:

PHP script is written that makes it possible to query the database through a HTML form. This will work as any other search
engine: the user enters a word in a textbox, hits enter, and the interface presents a result page with links to the pages
which contains the word that is searched for.
In this example, the results are displayed the order in which the pages are presented is selected by the number of search
words appeared in each document.
Declare an associative array $CommonWords that contains common words like ??is??, ??in??, ??was?? etc.
First convert all the search words in to lower case.
$search_keywords=strtolower(trim($keywords));

Next, we have to perform an explode operation on search words that will store each search word in an array.
The code is shown here.
$arrWords = explode(” “, $search_keywords);

Next, remove duplicate words in $arrWords.
$arrWords = array_unique($arrWords);
In a search operation, first we have to remove the common words like ??is??, ??in??, ??was?? ?? This refines our search criteria.
To implement this we store common words in an associative array $CommonWords.
Next, remove common words in the search words. Search words are stored in $searchWords and
common words are stored in $junkWords. Here is the code.

<?php

        $searchWords
=array();

        
$junkWords=array();

        foreach(
$arrWords as $word)

            
//remove common words

            
if(!$CommonWords[$word]){

                
$searchWords[]=$word;

            }else{

                
$junkWords[]=$word;

           }

?>



1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9
|
|
|
|