view examples/search/index.php @ 46:b7376319d25a

centralise db query even more
author Charlie Root
date Sun, 06 Jan 2019 12:15:42 -0500
parents 077b0a0a3e6d
children
line wrap: on
line source

<html>
<head>
<title>PHP Sample Search Engine</title>
</head>
<link rel="stylesheet" type="text/css" href="style.css">
<body OnLoad="document.searchForm.q.focus();">
<div id="search">
<form name="searchForm" action="index.php">

<?PHP

$query = urlencode($_GET ['q']);	// Get query term
$count = urlencode($_GET ['c']);	// Get result count

if($count < 1)
	$count = 10;	//do not allow zero or negative search results	

if($query == "")
	$startText = "Enter your search here!";
else
	$startText = urldecode($query);

echo "<input class=\"largeText\" type=\"text\" name=\"q\" size=\"50\" value=\"$startText\">";
echo "<input class=\"submitButton\" type=\"submit\" value=\"Search\"/>";
echo "<label for=\"c\">Number of Results:</label><input type=\"text\" name=\"c\" size=\"3\" value=\"$count\">";
echo "</form>";

if($query !="")
{
	include("resultsSet.php");
	
	//-----------------------------SPELL CHECK-----------------------------
	$spell = new resultsSet('spelling',$count);
	$xml = $spell->getXMLResults($query);
	foreach ($xml->resultset_spell->result as $result) {
		echo '<h3>Did you mean? <a href="index.php?q='.$result->suggestion.'">'.$result->suggestion.'</a></h3><br/>';
	}
	//Note, Yahoo spellcheck doesn't seem particularly good, but one example it detects is 'Seach' which it suggests as 'Search'
	
	echo "</div>";
	
	//-----------------------------WEB RESULTS-----------------------------
	$web = new resultsSet('web',$count);
	$xml = $web->getXMLResults($query);
	echo "<div id=\"left\">";
	echo "<h2>Web:</h2><br/>";
	foreach ($xml->resultset_web->result as $result) {
		echo '<a href="'.$result->clickurl.'">'.$result->title.'</a>';
		echo '<p>'.$result->abstract.'</p>';
		echo '<a href="'.$result->dispurl.'">'.$result->dispurl.'</a><hr />';
	} 
	echo "</div> ";

	//-----------------------------IMAGE RESULTS-----------------------------
	$images = new resultsSet('images',$count);
	$xml = $images->getXMLResults($query);
	echo "<div id=\"content\">";
	echo "<h2>Images:</h2><br/>";
	foreach ($xml->resultset_images->result as $result) {
		echo '<a href="'.$result->clickurl.'"><img src='.$result->clickurl.' alt="'.$result->filename.'"></a>';
	}
	echo "</div> ";

	//-----------------------------NEWS RESULTS-----------------------------
	$news = new resultsSet('news',$count);
	$xml = $news->getXMLResults($query);
	echo "<div id=\"right\">";
	echo "<h2>News:</h2><br/>";
	foreach ($xml->resultset_news->result as $result) {
		echo '<a href="'.$result->clickurl.'">'.$result->title.'</a>';
		echo '<p>'.$result->abstract.'</p>';
		echo '<p>Date: '.$result->date .'</p>';
		echo 'Source: <a href="'.$result->sourceurl.'">'.$result->sourceurl.'</a><hr />';
	}
	echo "</div> ";
}
?>