commit 96a12ecd4b88202adf133b13f4546fecc5ccf28d
parent 6a1b3d66d8800b396fcf8c3782a976248fc94995
Author: xfnw <xfnw@thunix.net>
Date: Wed, 16 Dec 2020 10:58:08 -0500
change scoring system to discourage long feeds of keywords
Diffstat:
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/index.php b/index.php
@@ -53,7 +53,9 @@ if (isset($_GET['q']) && preg_replace('/\s+/', '', $_GET['q']) != '') {
while ($row = $stmt->fetch()) {
$score = 0;
foreach ($terms as $param)
- $score = $score + substr_count(strtolower($row['content']),strtolower($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);
@@ -70,12 +72,12 @@ if (isset($_GET['q']) && preg_replace('/\s+/', '', $_GET['q']) != '') {
<div class='box'>
<a href="<?php echo htmlspecialchars($row['url']); ?>"><?php echo htmlspecialchars($row['title']); ?></a>
<br>
-<small>(score: <?php echo $row['score']; ?>) <?php echo htmlspecialchars($row['url']); ?></small>
+<small>(score: <?php echo round($row['score']); ?>) <?php echo htmlspecialchars($row['url']); ?></small>
<br>
...<?php
$content = $row['content'];
foreach ($terms as $param) {
- $pos = strpos($content, $param);
+ $pos = strpos(strtolower($content), strtolower($param));
if ($pos !== false) {
echo htmlspecialchars(substr($content,$pos-50,50));
echo '<strong>'.htmlspecialchars($param).'</strong>';