re: Search Engine.
| From: | Javier Montserat | Date: | Mon, 16 Sep 2002 11:17:05 +0000 |
| Subject: | re: Search Engine. | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-116504@lists.php.net to get a copy of this message | ||
Here's a really simple search function based around ereg() :-
<?php
// simple search
function search($searchTerm) {
$getAllResult = pg_exec($db,"SELECT oid, title FROM example");
$resultCount = pg_numrows($getAllResult);
for ($i = 0; $i < $resultCount; $i++) {
$oid[$i] = pg_result($getAllResult, $i, "oid");
$title[$i] = pg_result($getAllResult, $i, "title");
}
$matchingCount = 0;
for ($i = 0; $i < $resultCount; $i++) {
$found = ereg((strtolower($searchTerm)),(strtolower($title[$i])));
if ($found == true) {
$matching_oid[$matchingCount] = $oid[$i];
$matching_title[$matchingCount] = $title[$i];
$matchingCount++;
}
}
} // end search
?>
Not sure how efficient this method is (return entire result set / filter by search term). I'd be keen to hear how other people implement this.
Javier
_________________________________________________________________
Join the worlds largest e-mail service with MSN Hotmail. http://www.hotmail.com