Jump to content

PHP Site Search class, help please


smacpettit

Recommended Posts

Morning everyone,

 

I friend of mine has given me this script to have a look at but I cant seem to get any heads or tails of it, its a web site site search ive only ever done MYSQL searches before so any help would be greatly appreciated.

 

index.php

<?php

define ("AUTHOR", "Simon");
require_once("SiteSearch.php");

$search = new SiteSearch ();

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<HTML>
<HEAD>
<title><?=AUTHOR?></title>
<link rel="stylesheet" type="text/css" href="style.css" />
</HEAD>
<BODY>
<div id="container">
<h2><span id="author"><?=AUTHOR?></span></h2>
<form method="GET" action="<?=$_SERVER['PHP_SELF']?>">
<div id="searchBox">
	<table id="searchDetails">
		<tr><td>Search Term</td><td><input class="text" name="term" type="text" value="contribute" /></td></tr>
		<tr><td>Website</td><td><input class="text" name="url" type="text" value="http://ubuntu.com/" /></td></tr>
		<tr><td>Search Depth</td><td><select name="depth">
						<option value="1">1</option>
						<option value="2" selected>2</option>
						<option value="3">3</option>
						<option value="4">4</option>
						<option value="5">5</option>
					     </select></td></tr>
	</table>		
	<input type="submit" value="start search" />
</div>
</form>
<?php $results = $search->returnResults(); ?>
<h2>Showing <?=count($results)?> results</h2>
<div id="resultsBox">
<?php foreach ($results as $result) { ?>
	<div id="result">
	<h3 class="title"><?=$result['title']?></h3>
	<em class="date"><?=$result['date']?></em>
	<p class="desc"><?=$result['content']?></p>
	<span class="url"><?=$result['url']?></span>
	</div>
<?php } ?>
</div>
</div>
</BODY>
</HTML>

 

SiteSearch.php

 

class SiteSearch {

public function setUrl ($url) {

}

public function setTerm ($search) {

}

public function returnResults () {
	$result = array();

	/* Fake Results */
	for ($i=0; $i<10; $i++) 
	$result[$i] = array (
					"title"		=> ($i+1).": Example Page Title",
					"date"		=> "Date Found: 15.08.06 17:17:23",
					"content"	=> "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed turpis. In mattis aliquet felis. Nunc sagittis urna ac felis. Phasellus sed <span class=\"exactMatch\">contribute</span> velit. Donec orci sem, tempus pharetra, fermentum nec, pellentesque vitae, massa.",
					"url"		=> "http://example.domain.com/url"
				  );
	return $result;
}
}

?>

Link to comment
https://forums.phpfreaks.com/topic/167106-php-site-search-class-help-please/
Share on other sites

Have a look at http://www.sphider.eu/ as an example.

 

You need to crawl the site with a spider if you want to search the content. But you will only be able to do this on your own domain, unless you start looking into curl() to gather content from other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.