Exalead.php 1.65 KB
Newer Older
1
2
3
4
<?php

namespace app\Models\parserSkripte;
use App\Models\Searchengine;
Dominik Hebeler's avatar
Dominik Hebeler committed
5
use Log;
6
7
8
9
10
11
12
13
14
15

class Exalead extends Searchengine 
{
	public $results = [];

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

16
	public function loadResults ($result)
17
	{
Dominik Hebeler's avatar
Dominik Hebeler committed
18
19
20
21
22
23
		$result = preg_replace("/\r\n/si", "", $result);
		try {
			$content = simplexml_load_string($result);
		} catch (\Exception $e) {
			abort(500, "$result is not a valid xml string");
		}
24
		
Dominik Hebeler's avatar
Dominik Hebeler committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
		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;
		}
		$results->registerXPathNamespace($prefix,$namespace);
		$results = $results->xpath("//a:hits/a:Hit");
		foreach($results as $result)
		{
			$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;
			if(sizeOf($result->xpath("a:metas/a:Meta[@name='metadesc']/a:MetaString[@name='value']")) === 0)
				$descr = "";
			else
				$descr = $result->xpath("a:metas/a:Meta[@name='metadesc']/a:MetaString[@name='value']")[0]->__toString();
			$this->counter++;
			$this->results[] = new \App\Models\Result(
				$this->engine,
				$title,
				$link,
				$anzeigeLink,
				$descr,
				$this->gefVon,
				$this->counter
			);
		}
62
	}
Dominik Hebeler's avatar
Dominik Hebeler committed
63
}