searpl
setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
if (isset($_GET['q']) && preg_replace('/\s+/', '', $_GET['q']) != '') {
$sql = 'SELECT * FROM indexed WHERE 1=1';
$terms = explode(' ', trim(preg_replace('/\s+/', ' ', $_GET['q'])));
$params = array();
foreach ($terms as $term) {
if (substr($term, 0, 1) == '-') {
$sql = $sql . ' AND content NOT LIKE ?';
array_push($params,'%'.substr($term,1).'%');
} else {
$sql = $sql . ' AND content LIKE ?';
array_push($params,'%'.$term.'%');
}
}
$sql = $sql . ';';
$stmt = $db->prepare($sql);
$stmt->execute($params);
$rows = array();
$scores = array();
while ($row = $stmt->fetch()) {
$score = 0;
foreach ($terms as $param)
$score = $score + 100*(substr_count(strtolower($row['content']),strtolower($param)) / strlen($row['content']));
$score = $score + 5000*(substr_count(strtolower($row['url']),strtolower($param)) / strlen($row['url']));
$score = $score + 3000*(substr_count(strtolower($row['title']),strtolower($param)) / strlen($row['title']));
array_push($scores, $score);
$row['score'] = $score;
array_push($rows, $row);
}
array_multisort($scores, SORT_DESC, $rows);
$results = false;
foreach ($rows as $row) {
$results = true;
?>
(score: )
...'.htmlspecialchars($param).'';
echo htmlspecialchars(substr($content,$pos+strlen($param),50)).'...';
}
}
?>
No results.
';
} else {
?>
normal words inputted will be tags, a -tag will blacklist the tag and
there is also unsorted SQL LIKE syntax.
more stuff like site: coming soon!