Hi,
I'm was asked to create a search engine. The same search on data in a MySQL service. Right now it work, but the search query is not powerful. How I can improve it and make it a good search engine?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/main.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Search Results - Personal</title>
<!-- InstanceEndEditable -->
<link href="css_style.css" rel="stylesheet" type="text/css" />
<link href="print.css" type="text/css" rel="stylesheet" media="print">
<link rel="Shortcut Icon" href="favicon.ico"/> <!-- Added by me -->
</head>
<body>
<table width="1038" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td colspan="2"><img src="source_files/header.png" alt="header" width="1038" height="140" /></td>
</tr>
<tr>
<td colspan="2" bgcolor="#333333" class="menu_nav"><a href="index.html">. Home</a><a href="pam.html">. PAM</a><a href="fdbt.html">. FDBT</a><a href="itim.html">. ITIM</a><a href="portal.html">. Portal</a><a href="top.html">. TOP</a><a href="tror.html">. TROR</a> <a href="http://127.0.0.1/limesurvey/index.php?sid=85543&lang=en">. Feedback</a> <a href="search.php" target="_self">. Search</a></td>
</tr>
<tr>
<td width="178" valign="top" class="left_column"><!-- InstanceBeginEditable name="left_column" -->
<p> </p>
<ul><li></li>
</ul>
<!-- InstanceEndEditable --></td>
<td width="860" valign="top" class="right_column"><!-- InstanceBeginEditable name="right_column" -->
<h1 align="center" class="right_column">Search Results</h1>
<?php
$var = @$_GET['search_field']; // '@' supress error messages
if (ereg("^[A-z0-9+. -]*[']?[A-z0-9+. -]*$",$var))
{
$trimmed = trim($var);
}
else
{
//$testquery = FALSE;
echo "Invalid search term. Click back in your browser to return.";
exit;
}
//validation
if ($trimmed == "") // if the search box is empty
{
echo "<p>Please enter text in the search box. Click back in your browser to return.</p>";
exit;
}
// Database
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'guess';
// Connecting to database
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'direc_files';
mysql_select_db($dbname,$conn);
// Get timestamp before executing the query:
$start_time = getmicrotime();
// Query or search parameter
$result = mysql_query("SELECT * FROM index_files WHERE file_name LIKE \"%$trimmed%\" ORDER BY file_name ASC") or die("Couldn't execute query");
$numrows=mysql_num_rows($result);
/* Get timestamp when the query is finished: */
$end_time = getmicrotime();
// Specify how many results to display per page
$limit = 10;
if ($numrows == false)
{ // if began
echo "What you looking for does not exist.";
mysql_close($conn);
exit;
} // if end
else
{ // else began
// display what the person searched for
echo "<p>You searched for: " ."<strong>" .$var . "</strong>" . "</p>";
while( $row = mysql_fetch_array($result) ) // displaying the data
{ // while began
echo $row['file_name'] . " ";
echo '<a href="http://127.0.0.1/mysite/search' .$row['directory'] . '">' . "View</a>";
echo "<br>" . "\n" . "</br>";
echo "<br>" . "\n" . "</br>";
} // while end
} // else end
// freeing the memory
mysql_free_result($result);
// close mysql connection
mysql_close($conn);
/* Present how long it took the execute the query: */
echo "<strong>Query executed in ".(substr($end_time-$start_time,0,5))." seconds.</strong>";
/* Simple function for retrieving the current timestamp in microseconds: */
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
?>
<!-- InstanceEndEditable --></td>
</tr>
<tr>
<td colspan="2" class="footer"> Personal </td>
</tr>
</table>
</body>
<!-- InstanceEnd --></html>