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

namespace App\Models\parserSkripte;

use App\Models\Searchengine;

class Minisucher extends Searchengine
{
9
10
11
    public function __construct(\SimpleXMLElement $engine, \App\MetaGer $metager)
    {
        parent::__construct($engine, $metager);
Dominik Hebeler's avatar
Dominik Hebeler committed
12
13
14
15
        # 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");
        }
16
    }
17

18
19
20
21
22
23
24
25
26
27
    public function loadResults($content)
    {
        try {
            $content = simplexml_load_string($content);
        } catch (\Exception $e) {
            return;
        }
        if (!$content) {
            return;
        }
28

29
        $results = $content->xpath('//response/result/doc');
30

31

32
        $string = "";
33

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

41
42
                $title         = $result->xpath('//doc/arr[@name="title"]/str')[0]->__toString();
                $link          = $result->xpath('//doc/str[@name="url"]')[0]->__toString();
43
44
45
46
47
48
49
                $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);
50
51
52
53
54
55
56
57
58

                $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];

59
60
                $minism = simplexml_load_string($this->engine)["subcollections"];
                $subcollection = $result->xpath('//doc/str[@name="subcollection"]')[0]->__toString();
61

62
63
64
65
66
67
68
69
70
                if(!$subcollection) {
                    $gefVon = "<a href=\"https://metager.de\" target=\"_blank\" rel=\"noopener\">Minisucher: $minism </a>";
                } else {
                    $minism = array_map('strtolower', explode(', ', $minism));
                    $subcollection = array_map('strtolower', explode(' ', $subcollection));
                    $result = implode(', ', array_intersect($subcollection, $minism));
                    $gefVon = "<a href=\"https://metager.de\" target=\"_blank\" rel=\"noopener\">Minisucher: $result </a>";
                }
                
71
72
73
74
75
76
77
                $this->results[] = new \App\Models\Result(
                    $this->engine,
                    $title,
                    $link,
                    $link,
                    $descr,
                    $gefVon,
78
79
                    $counter,
                    $additionalInformation
80
81
82
83
84
85
86
87
88
                );
            } catch (\ErrorException $e) {
                continue;
            }
        }

    }

}