Click here to Skip to main content
12,360,471 members (59,997 online)
Click here to Skip to main content

Stats

75.5K views
13.7K downloads
113 bookmarked
Posted

Making a Search Engine

, 3 May 2013 CPOL
This article discusses the making of a search engine.
<?

$term=htmlspecialchars($_GET["q"]) ;
if ($term ){
$pieces =explode(" ",$term);
// Connecting, selecting database
$intialterm="";
$len= count($pieces);
for($k = 0, $l = count($pieces)-1; $k < $l; ++$k){
$intialterm.= $pieces[$k]." ";
}
$link = mysql_connect('localhost', 'root', 'root')
    or die('Could not connect: ' . mysql_error());
	

mysql_select_db('crawler') or die('Could not select database');
//echo $len;
if($len<=1){
// Performing SQL query
$query = "SELECT word FROM keyword_index where word  like  '$term%'  limit 7;";
$result = mysql_query($query) or die('you can not use illegal charecter');

// Printing results in HTML
echo '<table id=st >';
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo '<tr id=sr >';
    foreach ($line as $col_value) {
        ?>

		<td onclick="chg('<? echo $col_value ?>')"><p > 	
		<? echo $col_value ?> 
		</p></td>
		<?
    }
    echo "</tr>";
}
echo "</table>";}
else{
  // echo $intialterm;
 //echo '<u>'.   $pieces[$len-1];
$query = "SELECT word FROM keyword_index where word  like  '".$pieces[$len-1]."%' order by freq desc limit 7;";
$result = mysql_query($query) or die('you can not use illegal charecter');

// Printing results in HTML
echo '<table id=st >';
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo '<tr id=sr >';
    foreach ($line as $col_value) {
		  ?>

		<td onclick="chg('<? echo $intialterm.' '.$col_value ?>')"><p > 	
		<? echo '<b>'.$intialterm.'</b> '.$col_value ?> 
		</p> </td>
		<?
    }
    echo "</tr>";
}
echo "</table>";}



// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);
}

?>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

kburman6
Student
India India
I just love coding. But due to my studies it became very tough for me to manage both.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160621.1 | Last Updated 4 May 2013
Article Copyright 2013 by kburman6
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid