BASE.php 2.05 KB
Newer Older
1
2
3
<?php

namespace app\Models\parserSkripte;
4

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

8
class BASE extends Searchengine
9
{
10
11
    public $results = [];

12
    public function __construct($name, \StdClass $engine, \App\MetaGer $metager)
13
    {
14
        parent::__construct($name, $engine, $metager);
15
    }
16

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

Dominik Hebeler's avatar
Bugfix    
Dominik Hebeler committed
26
            $results = $content->xpath('//response/result/doc');
27
28
29
30
31
32
33
34
35
            foreach ($results as $result) {
                // searches for the fitting values of name as in
                // <str name = "dctitle">Digitisation of library collections</str>
                foreach ($result as $attribute) {
                    switch ((string) $attribute['name']) {
                        case 'dctitle':
                            $title = $attribute;
                            break;
                        case 'dclink':
Dominik Hebeler's avatar
Dominik Hebeler committed
36
                            $link = $attribute;
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
                            $anzeigeLink = $link;
                            break;
                        case 'dcdescription':
                            $descr = $attribute;
                            break;
                    }
                }
                if (isset($title) && isset($link) && isset($anzeigeLink) && isset($descr)) {
                    $this->counter++;
                    $this->results[] = new \App\Models\Result(
                        $this->engine,
                        $title,
                        $link,
                        $anzeigeLink,
                        $descr,
Dominik Hebeler's avatar
Dominik Hebeler committed
52
                        $this->engine->{"display-name"}, $this->engine->homepage,
53
54
55
56
57
                        $this->counter
                    );
                }
            }
        } catch (\Exception $e) {
58
            Log::error("A problem occurred parsing results from $this->name:\n" . $e->getMessage() . "\n" . $result);
59
60
            return;
        }
61
62
    }
}