Overture.php 4.08 KB
Newer Older
1
2
3
<?php

namespace app\Models\parserSkripte;
4

5
use App\Models\Searchengine;
6
use Log;
7

8
class Overture extends Searchengine
9
{
10
11
12
13
14
15
    public $results = [];

    public function __construct(\SimpleXMLElement $engine, \App\MetaGer $metager)
    {
        parent::__construct($engine, $metager);
    }
16

17
18
19
20
21
    public function loadResults($result)
    {
        $result = preg_replace("/\r\n/si", "", $result);
        try {
            $content = simplexml_load_string($result);
22
23
24
25
26
27
            if (!$content) {
                return;
            }

            $results = $content->xpath('//Results/ResultSet[@id="inktomi"]/Listing');
            foreach ($results as $result) {
28
29
                $title = $result["title"];
                $link = $result->{"ClickUrl"}->__toString();
30
                $anzeigeLink = $result["siteHost"];
31
                $descr = $result["description"];
32
33
34
35
36
37
38
                $this->counter++;
                $this->results[] = new \App\Models\Result(
                    $this->engine,
                    $title,
                    $link,
                    $anzeigeLink,
                    $descr,
39
40
                    $this->displayName,
                    $this->homepage,
41
42
43
44
45
46
47
                    $this->counter
                );
            }

            # Nun noch die Werbeergebnisse:
            $ads = $content->xpath('//Results/ResultSet[@id="searchResults"]/Listing');
            foreach ($ads as $ad) {
48
49
                $title = $ad["title"];
                $link = $ad->{"ClickUrl"}->__toString();
50
                $anzeigeLink = $ad["siteHost"];
51
                $descr = $ad["description"];
52
53
54
55
56
57
58
                $this->counter++;
                $this->ads[] = new \App\Models\Result(
                    $this->engine,
                    $title,
                    $link,
                    $anzeigeLink,
                    $descr,
59
                    $this->displayName, $this->homepage,
60
61
62
                    $this->counter
                );
            }
63
        } catch (\Exception $e) {
64
65
            Log::error("A problem occurred parsing results from $this->name:");
            Log::error($e->getMessage());
66
67
68
            return;
        }
    }
69
70
71

    public function getNext(\App\MetaGer $metager, $result)
    {
72
73
74
75
76
77
78
        $result = preg_replace("/\r\n/si", "", $result);
        try {
            $content = simplexml_load_string($result);
            if (!$content) {
                return;
            }
        } catch (\Exception $e) {
79
80
            Log::error("A problem occurred parsing results from $this->name:");
            Log::error($e->getMessage());
81
82
83
            return;
        }

84
        if (!$content) {
85
86
            return;
        }
87
88
89
90

        // Yahoo liefert, wenn es keine weiteren Ergebnisse hat immer wieder die gleichen Ergebnisse
        // Wir müssen also überprüfen, ob wir am Ende der Ergebnisse sind
        $resultCount = $content->xpath('//Results/ResultSet[@id="inktomi"]/MetaData/TotalHits');
91
        $results = $content->xpath('//Results/ResultSet[@id="inktomi"]/Listing');
92
        if (isset($resultCount[0]) && sizeof($results) > 0) {
93
            $resultCount = intval($resultCount[0]->__toString());
94
95
96
97
98
            $lastResultOnPage = intval($results[sizeof($results) - 1]["rank"]);
            if ($resultCount <= $lastResultOnPage) {
                return;
            }
        } else {
99
            return;
100
        }
101

102
103
104
105
106
107
108
109
110
111
112
113
114
        $nextArgs = $content->xpath('//Results/NextArgs');
        if (isset($nextArgs[0])) {
            $nextArgs = $nextArgs[0]->__toString();
        } else {
            $nextArgs = $content->xpath('//Results/ResultSet[@id="inktomi"]/NextArgs');
            if (isset($nextArgs[0])) {
                $nextArgs = $nextArgs[0]->__toString();
            } else {
                return;
            }
        }

        # Erstellen des neuen Suchmaschinenobjekts und anpassen des GetStrings:
115
        $next = new Overture(simplexml_load_string($this->engine), $metager);
116
        $next->getString = preg_replace("/&Keywords=.*?&/si", "&", $next->getString) . "&" . $nextArgs;
117
118
        $next->hash = md5($next->host . $next->getString . $next->port . $next->name);
        $this->next = $next;
119
    }
120
}