From 901024f43d5237fa8d7147b166df375d916bd0df Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Phil=20H=C3=B6fer?= <phil@suma-ev.de>
Date: Thu, 29 Sep 2016 08:12:21 +0200
Subject: [PATCH] WIP: combineResults separiert

---
 app/Http/Controllers/MetaGerSearch.php |  2 +-
 app/MetaGer.php                        | 56 ++++++++++++++++----------
 2 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/app/Http/Controllers/MetaGerSearch.php b/app/Http/Controllers/MetaGerSearch.php
index 86a423dfb..a7824f40b 100644
--- a/app/Http/Controllers/MetaGerSearch.php
+++ b/app/Http/Controllers/MetaGerSearch.php
@@ -28,7 +28,7 @@ class MetaGerSearch extends Controller
         $metager->rankAll();
 
         # Ergebnisse der Suchmaschinen kombinieren:
-        $metager->combineResults();
+        $metager->prepareResults();
 
         # Die Ausgabe erstellen:
         return $metager->createView();
diff --git a/app/MetaGer.php b/app/MetaGer.php
index 88183fbcc..3f06032ec 100644
--- a/app/MetaGer.php
+++ b/app/MetaGer.php
@@ -156,28 +156,18 @@ class MetaGer
         }
     }
 
-    public function combineResults()
+    public function prepareResults()
     {
-        foreach ($this->engines as $engine) {
-            if (isset($engine->next)) {
-                $this->next[] = $engine->next;
-            }
-            if (isset($engine->last)) {
-                $this->last[] = $engine->last;
-            }
-            foreach ($engine->results as $result) {
-                if ($result->valid) {
-                    $this->results[] = $result;
-                }
-            }
-            foreach ($engine->ads as $ad) {
-                $this->ads[] = $ad;
-            }
-            foreach ($engine->products as $product) {
-                $this->products[] = $product;
-            }
-        }
-
+        $engines = $this->engines;
+
+        // combine
+        $combinedResults = $this->combineResults($engines);
+        // sort
+        //$sortedResults = $this->sortResults($engines);
+        // filter
+        // augment (boost&adgoal)
+        // authorize
+        // misc (WiP)
         uasort($this->results, function ($a, $b) {
             if ($a->getRank() == $b->getRank()) {
                 return 0;
@@ -275,6 +265,30 @@ class MetaGer
 
     }
 
+    public function combineResults($engines)
+    {
+        foreach ($engines as $engine) {
+            if (isset($engine->next)) {
+                $this->next[] = $engine->next;
+            }
+            if (isset($engine->last)) {
+                $this->last[] = $engine->last;
+            }
+            foreach ($engine->results as $result) {
+                if ($result->valid) {
+                    $this->results[] = $result;
+                }
+            }
+            foreach ($engine->ads as $ad) {
+                $this->ads[] = $ad;
+            }
+            foreach ($engine->products as $product) {
+                $this->products[] = $product;
+            }
+        }
+
+    }
+
     public function parseBoost($results)
     {
         foreach ($results as $result) {
-- 
GitLab