Minisucher.php 2.98 KB
Newer Older
1
2
3
4
5
6
7
8
9
<?php

namespace App\Models\parserSkripte;

use App\Models\Searchengine;

class Minisucher extends Searchengine
{

10
11
12
    public function __construct(\SimpleXMLElement $engine, \App\MetaGer $metager)
    {
        parent::__construct($engine, $metager);
Dominik Hebeler's avatar
Dominik Hebeler committed
13
14
15
16
        # Für die Newssuche stellen wir die Minisucher auf eine Sortierung nach Datum um.
        if($metager->getFokus() === "nachrichten"){
            $this->getString .= "sort=" . $this->urlencode("documentDate desc");
        }
17
    }
18

19
20
21
22
23
24
25
26
27
28
29
    public function loadResults($content)
    {
        try {
            $content = simplexml_load_string($content);
        } catch (\Exception $e) {
            return;
        }
        if (!$content) {
            return;
        }
        $results = $content->xpath('//response/result/doc');
30

31
        $string = "";
32

33
34
35
36
37
38
        $counter         = 0;
        $providerCounter = [];
        foreach ($results as $result) {
            try {
                $counter++;
                $result = simplexml_load_string($result->saveXML());
39

40
41
42
43
44
45
46
47
48
                $title        = $result->xpath('//doc/arr[@name="title"]/str')[0]->__toString();
                $link         = $result->xpath('//doc/str[@name="url"]')[0]->__toString();
                $anzeigeLink  = $link;
                $descr        = "";
                $descriptions = $content->xpath("//response/lst[@name='highlighting']/lst[@name='$link']/arr[@name='content']/str");
                foreach ($descriptions as $description) {
                    $descr .= $description->__toString();
                }
                $descr    = strip_tags($descr);
49
50
51
52
53
54
55
56
57

                $dateString = $result->xpath('//doc/date[@name="documentDate"]')[0]->__toString();

                $date = date_create_from_format("Y-m-d\TH:i:s\Z", $dateString);

                $dateVal = $date->getTimestamp();

                $additionalInformation = ['date' => $dateVal];

58
                $provider = $result->xpath('//doc/str[@name="subcollection"]')[0]->__toString();
59

60
61
62
63
64
65
                if (isset($providerCounter[$provider]) && $providerCounter[$provider] > 10) {
                    continue;
                } else {
                    if (!isset($providerCounter[$provider])) {
                        $providerCounter[$provider] = 0;
                    }
66

67
68
                    $providerCounter[$provider] += 1;
                }
69

70
                if (isset($provider)) {
71
                    $gefVon = "<a href=\"https://metager.de\" target=\"_blank\" rel=\"noopener\">Minisucher: $provider</a>";
72
73
74
75
76
77
78
79
80
81
82
                } else {
                    $gefVon = $this->gefVon;
                }

                $this->results[] = new \App\Models\Result(
                    $this->engine,
                    $title,
                    $link,
                    $link,
                    $descr,
                    $gefVon,
83
84
                    $counter,
                    $additionalInformation
85
86
87
88
89
90
91
92
93
                );
            } catch (\ErrorException $e) {
                continue;
            }
        }

    }

}