Exalead.php 2.88 KB
Newer Older
1
2
3
<?php

namespace app\Models\parserSkripte;
4

5
6
use App\Models\Searchengine;

7
class Exalead extends Searchengine
8
{
9
10
11
12
13
14
15
16
17
18
19
20
    public $results = [];

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

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

25
26
27
28
29
30
31
32
33
34
            $results   = $content;
            $prefix    = "";
            $namespace = "";
            foreach ($results->getDocNamespaces() as $strPrefix => $strNamespace) {
                if (strlen($strPrefix) == 0) {
                    $prefix = "a"; //Assign an arbitrary namespace prefix.
                } else {
                    $prefix = "a";
                }
                $namespace = $strNamespace;
35
            }
36
            $results->registerXPathNamespace($prefix, $namespace);
37
            try {
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
                $results = $results->xpath("//a:searchResult/a:item");
            } catch (\ErrorException $e) {
                return;
            }
            foreach ($results as $result) {
                try {
                    $result->registerXPathNamespace($prefix, $namespace);
                    $title       = $result->xpath("a:metas/a:Meta[@name='title']/a:MetaString[@name='value']")[0]->__toString();
                    $link        = $result->xpath("a:metas/a:Meta[@name='url']/a:MetaString[@name='value']")[0]->__toString();
                    $anzeigeLink = $link;
                    $descr       = "";
                    if (sizeOf($result->xpath("a:metas/a:Meta[@name='metadesc']/a:MetaString[@name='value']")) === 0 && sizeOf($result->xpath("a:metas/a:Meta[@name='summary']/a:MetaText[@name='value']")) !== 0) {
                        $tmp = $result->xpath("a:metas/a:Meta[@name='summary']/a:MetaText[@name='value']");
                        foreach ($tmp as $el) {
                            $descr .= strip_tags($el->asXML());
                        }
                    } else {
                        $descr = $result->xpath("a:metas/a:Meta[@name='metadesc']/a:MetaString[@name='value']")[0]->__toString();
56
                    }
57

58
59
60
61
62
63
64
65
66
67
68
69
70
                    $this->counter++;
                    $this->results[] = new \App\Models\Result(
                        $this->engine,
                        $title,
                        $link,
                        $anzeigeLink,
                        $descr,
                        $this->gefVon,
                        $this->counter
                    );
                } catch (\ErrorException $e) {
                    continue;
                }
71
            }
72
73
74
        } catch (\Exception $e) {
            Log::error("A problem occurred parsing results from $this->name");
            return;
75
76
        }
    }
Dominik Hebeler's avatar
Dominik Hebeler committed
77
}