LibreY

- privacy respecting meta search engine
git clone git://git.acid.vegas/LibreY.git
Log | Files | Refs | Archive | README | LICENSE

commit 12f02198f9561a4fb48eea3f37227161da41210b
parent a00da6eb65749125e45444eed52e752f648741a3
Author: davidovski <david@davidovski.xyz>
Date: Wed, 30 Aug 2023 17:26:34 +0100

Add no results messages

Diffstat:
Mengines/text/google.php | 6++++++
Mengines/text/text.php | 24++++++++++++++++--------
Mmisc/search_engine.php | 3++-

3 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/engines/text/google.php b/engines/text/google.php
@@ -70,6 +70,12 @@
                 );
             }
 
+            if (empty($results) && !str_contains($response, "Our systems have detected unusual traffic from your computer network.")) {
+                $results["error"] = array(
+                    "message" => "There are no results. Please try different keywords!"
+                );
+            }
+
             return $results;
         }
     }
diff --git a/engines/text/text.php b/engines/text/text.php
@@ -36,23 +36,31 @@
 
             $results = $this->engine_request->get_results();
 
-            if ($this->special_request) {
-                $special_result = $this->special_request->get_results();
+            if (empty(count($results))) {
+                set_cooldown($this->engine, ($opts->request_cooldown ?? "1") * 60, $this->opts->cooldowns);
+            } else {
+                if ($this->special_request) {
+                    $special_result = $this->special_request->get_results();
 
-                if ($special_result)
-                    $results = array_merge(array($special_result), $results);
+                    if ($special_result)
+                        $results = array_merge(array($special_result), $results);
+                }
             }
 
-            if (count($results) <= 1)
-                set_cooldown($this->engine, ($opts->request_cooldown ?? "1") * 60, $this->opts->cooldowns);
-
             return $results;
         }
 
         public static function print_results($results) {
 
-            if (empty($results))
+            if (empty($results)) {
+                echo "<div class=\"text-result-container\"><p>An error occured fetching results</p></div>";
                 return;
+            }
+
+            if (array_key_exists("error", $results)) {
+                echo "<div class=\"text-result-container\"><p>" . $results["error"]["message"] . "</p></div>";
+                return;
+            }
 
             $special = $results[0];
 
diff --git a/misc/search_engine.php b/misc/search_engine.php
@@ -152,8 +152,9 @@
         } while ($running);
 
         $results = $search_category->get_results();
+        error_log(print_r($results, true));
 
-        if (count($results) <= 1) {
+        if (empty($results)) {
             require "engines/librex/fallback.php";
             $results = get_librex_results($opts);
         }