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

namespace app\Models\parserSkripte;
4

5
use App\Models\Searchengine;
Dominik Hebeler's avatar
Dominik Hebeler committed
6
use Log;
7

8
class Exalead extends Searchengine
9
{
10
11
12
13
14
15
16
17
18
19
20
21
    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);
22
23
24
25
26
27
28
29
30
31
32
33
34
            if (!$content) {
                return;
            }
            $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
                $results = $results->xpath("//a:hits/a:Hit");
39
40
41
42
43
44
45
            } 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();
46
                    $link        = $result["url"]->__toString();
47
48
49
50
51
52
53
54
55
                    $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
                    $this->counter++;
                    $this->results[] = new \App\Models\Result(
                        $this->engine,
                        $title,
                        $link,
                        $anzeigeLink,
                        $descr,
64
                        $this->displayName,$this->homepage,
65
66
67
68
69
                        $this->counter
                    );
                } catch (\ErrorException $e) {
                    continue;
                }
70
            }
71
        } catch (\Exception $e) {
72
73
            Log::error("A problem occurred parsing results from $this->name:");
            Log::error($e->getMessage());
74
            return;
75
76
        }
    }
Dominik Hebeler's avatar
Dominik Hebeler committed
77
}