LibreY

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

commit f50022f7807683aaaa4e72dd78123e575baf6a6c
parent 0fd041a35372a0b5aed12be2be2097bddb66982b
Author: davidovski <david@davidovski.xyz>
Date: Fri, 25 Aug 2023 17:39:08 +0100

added request cooldowns for google

Diffstat:
Mconfig.php.example | 3++-
Mengines/librex/fallback.php | 4+---
Mengines/text/google.php | 3+--
Mengines/text/text.php | 17++++++++++++++---
Mmisc/search_engine.php | 3+++

5 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/config.php.example b/config.php.example
@@ -151,7 +151,8 @@
             CURLOPT_REDIR_PROTOCOLS => CURLPROTO_HTTPS | CURLPROTO_HTTP,
             CURLOPT_MAXREDIRS => 5,
             CURLOPT_TIMEOUT => 3,
-            CURLOPT_VERBOSE => false
+            CURLOPT_VERBOSE => false,
+            CURLOPT_FOLLOWLOCATION => true
         )
     );
 ?>
diff --git a/engines/librex/fallback.php b/engines/librex/fallback.php
@@ -36,9 +36,7 @@
         if (!$opts->do_fallback)
             return array();
 
-        require "misc/cooldowns.php";
-
-        $cooldowns = load_cooldowns();
+        $cooldowns = $opts->cooldowns;
         error_log("loaded" . count($cooldowns));
         error_log(print_r($cooldowns,true));
 
diff --git a/engines/text/google.php b/engines/text/google.php
@@ -1,7 +1,6 @@
 <?php
     class GoogleRequest extends EngineRequest {
-        function get_request_url()
-        {
+        public function get_request_url() {
 
             $query_encoded = str_replace("%22", "\"", urlencode($this->query));
             $results = array();
diff --git a/engines/text/text.php b/engines/text/text.php
@@ -5,19 +5,23 @@
             $this->page = $opts->page;
             $this->opts = $opts;
 
-            $engine = $opts->preferred_engines["text"] ?? "google";
+            $this->engine = $opts->preferred_engines["text"] ?? "google";
 
             $query_parts = explode(" ", $this->query);
             $last_word_query = end($query_parts);
             if (substr($this->query, 0, 1) == "!" || substr($last_word_query, 0, 1) == "!")
                 check_ddg_bang($this->query, $opts);
 
-            if ($engine == "google") {
+            if (has_cooldown($this->engine, $this->opts->cooldowns))
+                return;
+
+            if ($this->engine == "google") {
+                
                 require "engines/text/google.php";
                 $this->engine_request = new GoogleRequest($opts, $mh);
             }
 
-            if ($engine == "duckduckgo") {
+            if ($this->engine == "duckduckgo") {
                 require "engines/text/duckduckgo.php";
                 $this->engine_request = new DuckDuckGoRequest($opts, $mh);
             }
@@ -27,6 +31,10 @@
         }
 
         public function get_results() {
+            if (!$this->engine_request)
+                return array();
+
+            error_log("fetching googl results");
             $results = $this->engine_request->get_results();
 
             if ($this->special_request) {
@@ -36,6 +44,9 @@
                     $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;
         }
 
diff --git a/misc/search_engine.php b/misc/search_engine.php
@@ -111,6 +111,9 @@
     }
 
     function fetch_search_results($opts, $do_print) {
+        require "misc/cooldowns.php";
+        $opts->cooldowns = load_cooldowns();
+
         $start_time = microtime(true);
         $mh = curl_multi_init();
         $search_category = init_search($opts, $mh);