Commit a6387d93 authored by Dominik Hebeler's avatar Dominik Hebeler

Änderungen in der Pagination eingebaut.

Jede Suchmaschine kann nun die Funktionen getNext() bzw. getLast() einbinden, mit denen sie
ein entsprechendes Suchmaschinenobjekt für die nächste bzw. letzte Suche erstellen
und speichern können.
parent bc2f6b50
......@@ -13,7 +13,7 @@ class Search extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
protected $hash, $host, $port, $name, $getString, $useragent, $fp, $sumaFile;
protected $hash, $host, $port, $name, $getString, $useragent, $fp;
protected $buffer_length = 8192;
/**
......@@ -21,7 +21,7 @@ class Search extends Job implements ShouldQueue
*
* @return void
*/
public function __construct($hash, $host, $port, $name, $getString, $useragent, $sumaFile)
public function __construct($hash, $host, $port, $name, $getString, $useragent)
{
$this->hash = $hash;
$this->host = $host;
......@@ -29,7 +29,6 @@ class Search extends Job implements ShouldQueue
$this->name = $name;
$this->getString = $getString;
$this->useragent = $useragent;
$this->sumaFile = $sumaFile;
}
/**
......@@ -50,13 +49,6 @@ class Search extends Job implements ShouldQueue
}
}
public function disable($sumaFile, $message)
{
$xml = simplexml_load_file($sumaFile);
$xml->xpath("//sumas/suma[@name='" . $this->name . "']")['0']['disabled'] = date(DATE_RFC822, mktime(date("H")+1,date("i"), date("s"), date("m"), date("d"), date("Y")));
$xml->saveXML($sumaFile);
}
private function readAnswer ()
{
$time = microtime(true);
......
This diff is collapsed.
......@@ -5,8 +5,9 @@ namespace App\Models;
class Result
{
public function __construct(\SimpleXMLElement $provider, $titel, $link, $anzeigeLink, $descr, $gefVon, $sourceRank, $partnershop = false, $image = "", $price = 0)
public function __construct($provider, $titel, $link, $anzeigeLink, $descr, $gefVon, $sourceRank, $partnershop = false, $image = "", $price = 0)
{
$provider = simplexml_load_string($provider);
$this->titel = strip_tags(trim($titel));
$this->link = trim($link);
$this->anzeigeLink = trim($anzeigeLink);
......
......@@ -36,16 +36,12 @@ abstract class Searchengine
$this->homepage = "https://metager.de";
}
$this->engine = $engine;
$this->engine = $engine->asXML();
if (!isset($this->cacheDuration)) {
$this->cacheDuration = 60;
}
# Wir registrieren die Benutzung dieser Suchmaschine
$this->uses = intval(Redis::hget($this->name, "uses")) + 1;
Redis::hset($this->name, "uses", $this->uses);
# Eine Suchmaschine kann automatisch temporär deaktiviert werden, wenn es Verbindungsprobleme gab:
if (isset($this->disabled) && strtotime($this->disabled) <= time()) {
# In diesem Fall ist der Timeout der Suchmaschine abgelaufen.
......@@ -75,21 +71,32 @@ abstract class Searchengine
$this->getString = $this->generateGetString($q, $metager->getUrl(), $metager->getLanguage(), $metager->getCategory());
$this->hash = md5($this->host . $this->getString . $this->port . $this->name);
$this->resultHash = $metager->getHashCode();
}
abstract public function loadResults($result);
public function getLast(MetaGer $metager, $result){
}
public function getNext(MetaGer $metager, $result){
}
public function startSearch(\App\MetaGer $metager)
{
if (Cache::has($this->hash)) {
$this->cached = true;
$this->retrieveResults();
$this->retrieveResults($metager);
} else {
# Die Anfragen an die Suchmaschinen werden nun von der Laravel-Queue bearbeitet:
# Hinweis: solange in der .env der QUEUE_DRIVER auf "sync" gestellt ist, werden die Abfragen
# nacheinander abgeschickt.
# Sollen diese Parallel verarbeitet werden, muss ein anderer QUEUE_DRIVER verwendet werden.
# siehe auch: https://laravel.com/docs/5.2/queues
$this->dispatch(new Search($this->resultHash, $this->host, $this->port, $this->name, $this->getString, $this->useragent, $metager->getSumaFile()));
$this->dispatch(new Search($this->resultHash, $this->host, $this->port, $this->name, $this->getString, $this->useragent));
}
}
abstract public function loadResults($result);
public function rank(\App\MetaGer $metager)
{
foreach ($this->results as $result) {
......@@ -130,7 +137,7 @@ abstract class Searchengine
}
}
public function retrieveResults()
public function retrieveResults(MetaGer $metager)
{
if ($this->loaded) {
return true;
......@@ -149,6 +156,8 @@ abstract class Searchengine
if ($body !== "") {
$this->loadResults($body);
$this->getNext($metager, $body);
$this->getLast($metager, $body);
$this->loaded = true;
Redis::hdel('search.' . $this->hash, $this->name);
return true;
......
......@@ -62,4 +62,58 @@ class Overture extends Searchengine
);
}
}
public function getLast(\App\MetaGer $metager, $result)
{
# Auslesen der Argumente für die nächste Suchseite:
$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");
}
$lastArgs = $content->xpath('//Results/PrevArgs');
if (isset($lastArgs[0])) {
$lastArgs = $lastArgs[0]->__toString();
} else {
$lastArgs = $content->xpath('//Results/ResultSet[@id="inktomi"]/PrevArgs');
if (isset($lastArgs[0])) {
$lastArgs = $lastArgs[0]->__toString();
} else {
return;
}
}
# Erstellen des neuen Suchmaschinenobjekts und anpassen des GetStrings:
$last = new Overture(simplexml_load_string($this->engine), $metager);
$last->getString = preg_replace("/&Keywords=.*?&/si", "&", $last->getString) . "&" . $lastArgs;
$this->last = $last;
}
public function getNext(\App\MetaGer $metager, $result)
{
# Auslesen der Argumente für die nächste Suchseite:
$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");
}
$nextArgs = $content->xpath('//Results/NextArgs');
if (isset($nextArgs[0])) {
$nextArgs = $nextArgs[0]->__toString();
} else {
$nextArgs = $content->xpath('//Results/ResultSet[@id="inktomi"]/NextArgs');
if (isset($nextArgs[0])) {
$nextArgs = $nextArgs[0]->__toString();
} else {
return;
}
}
# Erstellen des neuen Suchmaschinenobjekts und anpassen des GetStrings:
$next = new Overture(simplexml_load_string($this->engine), $metager);
$next->getString = preg_replace("/&Keywords=.*?&/si", "&", $next->getString) . "&" . $nextArgs;
$this->next = $next;
}
}
......@@ -51,4 +51,22 @@ class Yandex extends Searchengine
);
}
}
public function getLast(\App\MetaGer $metager, $result)
{
if( $metager->getPage() <= 1 )
return;
$next = new Yandex(simplexml_load_string($this->engine), $metager);
$next->getString .= "page=" . ($metager->getPage() -1 );
$this->next = $next;
}
public function getNext(\App\MetaGer $metager, $result)
{
if( count($this->results) <= 0 )
return;
$next = new Yandex(simplexml_load_string($this->engine), $metager);
$next->getString .= "page=" . $metager->getPage();
$this->next = $next;
}
}
......@@ -21,7 +21,7 @@
</div>
@foreach( $metager->request->all() as $key => $value)
@if($key !== "eingabe" && $key !== "page")
@if($key !== "eingabe" && $key !== "page" && $key !== "next")
<input type='hidden' name='{{ $key }}' value='{{ $value }}' form='submitForm' />
@endif
@endforeach
......
......@@ -15,7 +15,6 @@
<meta content="{{ getmypid() }}" name="p" />
<meta content="{{ $eingabe }}" name="q" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="referrer" content="no-referrer" />
<link rel="search" type="application/opensearchdescription+xml" title="MetaGer: Sicher suchen &amp; finden, Privatsph&auml;re sch&uuml;tzen" href="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), action('StartpageController@loadPlugin', ['params' => base64_encode(serialize(Request::all()))])) }}">
</head>
......@@ -24,9 +23,15 @@
@include('layouts.researchandtabs')
@else
<div class="tab-content container-fluid">
@yield('results')
@yield('results')
</div>
@endif
<nav aria-label="...">
<ul class="pager">
<li @if($metager->lastSearchLink() === "#") class="disabled" @endif><a href="{{ $metager->lastSearchLink() }}">Zurück</a></li>
<li @if($metager->nextSearchLink() === "#") class="disabled" @endif><a href="{{ $metager->nextSearchLink() }}">Weiter Suchen</a></li>
</ul>
</nav>
<footer>
<div class="row">
<div class="col-xs-6">
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment