searpl

a small php sqlite search engine. <a href="https://thunix.net/~xfnw/search">see it in action</a>
Log | Files | Refs | README

commit 79ba217da2ee6822a6114e5f384716eeb5df5013
parent c62b48ae1f52c3f1529ed2a41d3f35fe705f3b21
Author: xfnw <xfnw@thunix.net>
Date:   Mon, 14 Dec 2020 17:50:06 -0500

sort them

Diffstat:
Mindex.php | 19++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/index.php b/index.php @@ -47,14 +47,31 @@ if (isset($_GET['q']) && preg_replace('/\s+/', '', $_GET['q']) != '') { $stmt = $db->prepare($sql); $stmt->execute($params); - $results = false; + + $rows = array(); + $scores = array(); while ($row = $stmt->fetch()) { + $score = 0; + foreach ($terms as $param) + $score = $score + substr_count($row['content'],$param); + 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; + if (substr($row['url'],-1,1)=='/') + continue ?> <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> +<br> ...<?php $content = $row['content']; foreach ($terms as $param) {