Commit 46ae5c4a authored by Dominik Hebeler's avatar Dominik Hebeler

Merge branch '860-filter-options-for-websearch-aswell' into 'development'

Resolve "Filter Options for Websearch aswell"

Closes #860

See merge request !1367
parents 022f804c 42e31f10
...@@ -28,6 +28,7 @@ class MetaGer ...@@ -28,6 +28,7 @@ class MetaGer
protected $stopWords = []; protected $stopWords = [];
protected $phrases = []; protected $phrases = [];
protected $engines = []; protected $engines = [];
protected $totalResults = 0;
protected $results = []; protected $results = [];
protected $queryFilter = []; protected $queryFilter = [];
protected $parameterFilter = []; protected $parameterFilter = [];
...@@ -562,6 +563,21 @@ class MetaGer ...@@ -562,6 +563,21 @@ class MetaGer
} }
} }
} }
# Check if this engine should only be active when filter is used
if ($this->sumaFile->sumas->{$suma}->{"filter-opt-in"}) {
# This search engine should only be used when a parameter filter of it is used
$validTmp = false;
foreach ($this->parameterFilter as $filterName => $filter) {
if (!empty($filter->sumas->{$suma})) {
$validTmp = true;
break;
}
}
if (!$validTmp) {
$valid = false;
}
}
# If it can we add it # If it can we add it
if ($valid) { if ($valid) {
$this->enabledSearchengines[$suma] = $this->sumaFile->sumas->{$suma}; $this->enabledSearchengines[$suma] = $this->sumaFile->sumas->{$suma};
...@@ -621,6 +637,11 @@ class MetaGer ...@@ -621,6 +637,11 @@ class MetaGer
$this->waitForResults($enginesToLoad, $overtureEnabled, $canBreak); $this->waitForResults($enginesToLoad, $overtureEnabled, $canBreak);
$this->retrieveResults($engines); $this->retrieveResults($engines);
foreach ($engines as $engine) {
if (!empty($engine->totalResults) && $engine->totalResults > $this->totalResults) {
$this->totalResults = $engine->totalResults;
}
}
} }
# Spezielle Suchen und Sumas # Spezielle Suchen und Sumas
...@@ -685,6 +706,14 @@ class MetaGer ...@@ -685,6 +706,14 @@ class MetaGer
$availableFilter[$filterName] = $filter; $availableFilter[$filterName] = $filter;
} }
} }
# We will also add the filter from the opt-in search engines (the searchengines that are only used when a filter of it is too)
foreach ($this->sumaFile->foki->{$this->fokus}->sumas as $suma) {
if ($this->sumaFile->sumas->{$suma}->{"filter-opt-in"}) {
if (!empty($filter->sumas->{$suma})) {
$availableFilter[$filterName] = $filter;
}
}
}
} }
return $availableFilter; return $availableFilter;
...@@ -1541,6 +1570,11 @@ class MetaGer ...@@ -1541,6 +1570,11 @@ class MetaGer
return $this->sumaFile; return $this->sumaFile;
} }
public function getTotalResultCount()
{
return number_format($this->totalResults, 0, ",", ".");
}
public function getQueryFilter() public function getQueryFilter()
{ {
return $this->queryFilter; return $this->queryFilter;
......
...@@ -15,6 +15,7 @@ abstract class Searchengine ...@@ -15,6 +15,7 @@ abstract class Searchengine
public $getString = ""; # Der String für die Get-Anfrage public $getString = ""; # Der String für die Get-Anfrage
public $engine; # Die ursprüngliche Engine XML public $engine; # Die ursprüngliche Engine XML
public $totalResults = 0; # How many Results the Searchengine has found
public $results = []; # Die geladenen Ergebnisse public $results = []; # Die geladenen Ergebnisse
public $ads = []; # Die geladenen Werbungen public $ads = []; # Die geladenen Werbungen
public $products = []; # Die geladenen Produkte public $products = []; # Die geladenen Produkte
...@@ -48,7 +49,7 @@ abstract class Searchengine ...@@ -48,7 +49,7 @@ abstract class Searchengine
# Cache Standarddauer 60 # Cache Standarddauer 60
$this->cacheDuration = 60; $this->cacheDuration = 60;
if (!empty($engine->{"cache-duration"}) && $engine->{"cache-duration"} >= 0) { if (isset($engine->{"cache-duration"}) && $engine->{"cache-duration"} !== -1) {
$this->cacheDuration = $engine->{"cache-duration"}; $this->cacheDuration = $engine->{"cache-duration"};
} }
...@@ -183,6 +184,10 @@ abstract class Searchengine ...@@ -183,6 +184,10 @@ abstract class Searchengine
{ {
foreach ($this->results as $result) { foreach ($this->results as $result) {
$result->rank($eingabe); $result->rank($eingabe);
if (str_contains($this->engine->{"display-name"}, "Yahoo")) {
#die(var_dump($result));
}
} }
} }
...@@ -199,6 +204,7 @@ abstract class Searchengine ...@@ -199,6 +204,7 @@ abstract class Searchengine
} }
$body = ""; $body = "";
if ($this->canCache && $this->cacheDuration > 0 && Cache::has($this->hash)) { if ($this->canCache && $this->cacheDuration > 0 && Cache::has($this->hash)) {
$body = Cache::get($this->hash); $body = Cache::get($this->hash);
} elseif (Redis::hexists('search.' . $this->resultHash, $this->name)) { } elseif (Redis::hexists('search.' . $this->resultHash, $this->name)) {
......
<?php
namespace app\Models\parserSkripte;
use App\Models\Searchengine;
use Log;
class Bing extends Searchengine
{
public $results = [];
public function __construct($name, \stdClass $engine, \App\MetaGer $metager)
{
parent::__construct($name, $engine, $metager);
}
public function loadResults($result)
{
try {
$results = json_decode($result);
$this->totalResults = $results->webPages->totalEstimatedMatches;
$results = $results->webPages->value;
foreach ($results as $result) {
$title = $result->name;
$link = $result->url;
$anzeigeLink = $result->displayUrl;
$descr = $result->snippet;
$this->counter++;
$this->results[] = new \App\Models\Result(
$this->engine,
$title,
$link,
$anzeigeLink,
$descr,
$this->engine->{"display-name"}, $this->engine->homepage,
$this->counter,
[]
);
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name:");
Log::error($e->getMessage());
return;
}
}
public function getNext(\App\MetaGer $metager, $result)
{
try {
$results = json_decode($result);
$totalMatches = $results->webPages->totalEstimatedMatches;
$newEngine = unserialize(serialize($this->engine));
$perPage = $newEngine->{"get-parameter"}->count;
$offset = 0;
if (empty($newEngine->{"get-parameter"}->offset)) {
$offset = $perPage;
} else {
$offset = $newEngine->{"get-parameter"}->offset + $perPage;
}
if ($totalMatches < ($offset + $perPage)) {
return;
} else {
$newEngine->{"get-parameter"}->offset = $offset;
}
$next = new Bing($this->name, $newEngine, $metager);
$this->next = $next;
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name:");
Log::error($e->getMessage());
return;
}
}
}
...@@ -18,6 +18,7 @@ class BingBilder extends Searchengine ...@@ -18,6 +18,7 @@ class BingBilder extends Searchengine
{ {
try { try {
$results = json_decode($result); $results = json_decode($result);
$this->totalResults = $results->totalEstimatedMatches;
$results = $results->value; $results = $results->value;
foreach ($results as $result) { foreach ($results as $result) {
......
...@@ -25,7 +25,14 @@ class Overture extends Searchengine ...@@ -25,7 +25,14 @@ class Overture extends Searchengine
if (!$content) { if (!$content) {
return; return;
} }
# Yahoo gives us the total Result Count
$resultCount = $content->xpath('//Results/ResultSet[@id="inktomi"]/MetaData/TotalHits');
if (sizeof($resultCount) > 0) {
$resultCount = intval($resultCount[0]->__toString());
} else {
$resultCount = 0;
}
$this->totalResults = $resultCount;
$results = $content->xpath('//Results/ResultSet[@id="inktomi"]/Listing'); $results = $content->xpath('//Results/ResultSet[@id="inktomi"]/Listing');
foreach ($results as $result) { foreach ($results as $result) {
$title = $result["title"]; $title = $result["title"];
...@@ -40,8 +47,9 @@ class Overture extends Searchengine ...@@ -40,8 +47,9 @@ class Overture extends Searchengine
$anzeigeLink, $anzeigeLink,
$descr, $descr,
$this->engine->{"display-name"}, $this->engine->{"display-name"},
$this->engine->homepage, $this->engine->{"homepage"},
$this->counter $this->counter,
[]
); );
} }
...@@ -59,8 +67,10 @@ class Overture extends Searchengine ...@@ -59,8 +67,10 @@ class Overture extends Searchengine
$link, $link,
$anzeigeLink, $anzeigeLink,
$descr, $descr,
$this->engine->{"display-name"}, $this->engine->homepage, $this->engine->{"display-name"},
$this->counter $this->engine->{"homepage"},
$this->counter,
[]
); );
} }
} catch (\Exception $e) { } catch (\Exception $e) {
......
...@@ -22,7 +22,9 @@ return [ ...@@ -22,7 +22,9 @@ return [
'sitesearch.success' => 'Sie führen eine Sitesearch durch. Es werden nur Ergebnisse von der Seite: ":site" angezeigt.', 'sitesearch.success' => 'Sie führen eine Sitesearch durch. Es werden nur Ergebnisse von der Seite: ":site" angezeigt.',
'feedback' => 'Nichts Passendes dabei? Geben Sie uns Feedback: ', 'feedback' => 'Nichts Passendes dabei? Geben Sie uns Feedback: ',
'results' => "Ergebnisse",
'filter.noFilter' => 'Alle', 'filter.noFilter' => 'Alle',
'filter.reset' => 'Filter zurücksetzen',
'filter.sitesearch' => 'Sitesearch', 'filter.sitesearch' => 'Sitesearch',
'filter.safesearch' => "SafeSearch", 'filter.safesearch' => "SafeSearch",
...@@ -79,4 +81,44 @@ return [ ...@@ -79,4 +81,44 @@ return [
"filter.freshness.day" => "Letzte 24h", "filter.freshness.day" => "Letzte 24h",
"filter.freshness.week" => "Letzte Woche", "filter.freshness.week" => "Letzte Woche",
"filter.freshness.month" => "Letzter Monat", "filter.freshness.month" => "Letzter Monat",
"filter.market" => "Sprache",
"filter.market.ga" => "Deutsch (Österreich)",
"filter.market.gg" => "Deutsch (Deutschland)",
"filter.market.gs" => "Deutsch (Schweiz)",
"filter.market.ea" => "Englisch (Australien)",
"filter.market.ec" => "Englisch (Kanada)",
"filter.market.ei" => "Englisch (Indien)",
"filter.market.ein" => "Englisch (Indonesien)",
"filter.market.em" => "Englisch (Malaysia)",
"filter.market.enz" => "Englisch (Neuseeland)",
"filter.market.ep" => "Englisch (Philippinen)",
"filter.market.esa" => "Englisch (Süd-Afrika)",
"filter.market.euk" => "Englisch (UK)",
"filter.market.eus" => "Englisch (US)",
"filter.market.sa" => "Spanisch (Argentinien)",
"filter.market.sc" => "Spanisch (Chile)",
"filter.market.sm" => "Spanisch (Mexiko)",
"filter.market.ss" => "Spanisch (Spanien)",
"filter.market.sus" => "Spanisch (US)",
"filter.market.fb" => "Französisch (Belgien)",
"filter.market.fc" => "Französisch (Kanada)",
"filter.market.ff" => "Französisch (Frankreich)",
"filter.market.fs" => "Französisch (Schweiz)",
"filter.market.ii" => "Italienisch (Italien)",
"filter.market.db" => "Niederländisch (Belgien)",
"filter.market.dn" => "Niederländisch (Niederlande)",
"filter.market.pp" => "Polnisch (Polen)",
"filter.market.pb" => "Portugiesisch (Brasilien)",
"filter.market.dd" => "Dänisch (Dänemark)",
"filter.market.fif" => "Finnisch (Finnland)",
"filter.market.nn" => "Norwegisch (Norwegen)",
"filter.market.scs" => "Schwedisch (Schweden)",
"filter.market.rr" => "Russisch (Russland)",
"filter.market.jj" => "Japanisch (Japan)",
"filter.market.kk" => "Koreanisch (Korea)",
"filter.market.tt" => "Türkisch (Türkei)",
"filter.market.chk" => "Chinesisch (Hong Kong SAR)",
"filter.market.cc" => "Chinesisch (China)",
"filter.market.ct" => "Chinesisch (Taiwan)",
]; ];
...@@ -77,6 +77,7 @@ body { ...@@ -77,6 +77,7 @@ body {
background: -webkit-gradient(linear, left top, right top, from(@scrollfade-color), color-stop(fade(@scrollfade-color, 80%)), to(fade(@scrollfade-color, 0%))); background: -webkit-gradient(linear, left top, right top, from(@scrollfade-color), color-stop(fade(@scrollfade-color, 80%)), to(fade(@scrollfade-color, 0%)));
background: linear-gradient(to right, @scrollfade-color, fade(@scrollfade-color, 80%), fade(@scrollfade-color, 0%)); background: linear-gradient(to right, @scrollfade-color, fade(@scrollfade-color, 80%), fade(@scrollfade-color, 0%));
left: 1px; left: 1px;
margin-left: -20px;
} }
&right { &right {
background: -webkit-gradient(linear, right top, left top, from(@scrollfade-color), color-stop(fade(@scrollfade-color, 80%)), to(fade(@scrollfade-color, 0%))); background: -webkit-gradient(linear, right top, left top, from(@scrollfade-color), color-stop(fade(@scrollfade-color, 80%)), to(fade(@scrollfade-color, 0%)));
......
...@@ -483,8 +483,12 @@ a { ...@@ -483,8 +483,12 @@ a {
#options { #options {
grid-area: options; grid-area: options;
display: flex; background-color: white;
justify-content: left; max-width: @results-width-max;
padding: 0 8px;
@media(max-width: @screen-mobile){
.card;
}
input[type=checkbox]{ input[type=checkbox]{
display: none; display: none;
} }
...@@ -498,17 +502,33 @@ a { ...@@ -498,17 +502,33 @@ a {
max-height:200px; max-height:200px;
transform: scaleY(1); transform: scaleY(1);
} }
#toggle-box {
display: flex;
align-items: center;
#result-count {
flex-grow: 1;
text-align: right;
}
#options-reset {
margin-left: 10px;
}
.option-toggle {
text-align: center;
label{
font-weight: normal;
margin-bottom: 0;
}
}
}
#options-box{ #options-box{
width: 100%; width: 100%;
max-width: 700px; display: flex;
background-color: white; justify-content: left;
border-bottom: 1px solid #ccc;
@media(max-width: @screen-mobile){
.card;
}
overflow: hidden; overflow: hidden;
overflow-x: auto; overflow-x: auto;
padding: 8px; border-bottom: 1px solid #ccc;
padding-bottom: 8px;
padding-top: 8px;
#options-items { #options-items {
display: -ms-flexbox; display: -ms-flexbox;
display: flex; display: flex;
...@@ -531,10 +551,9 @@ a { ...@@ -531,10 +551,9 @@ a {
border-radius: 5px; border-radius: 5px;
} }
} }
} .option-selector:nth-child(1){
#options-reset { margin-left: 0;
margin-left: 10px; }
margin-bottom: 8px;
} }
} }
} }
...@@ -549,7 +568,7 @@ a { ...@@ -549,7 +568,7 @@ a {
} }
footer.resultPageFooter { footer.resultPageFooter {
max-width: 700px; max-width: @results-width-max;
margin-top: 20px; margin-top: 20px;
@media (max-width: (2 * @results-margin-left + @results-width-max - 1px)) { @media (max-width: (2 * @results-margin-left + @results-width-max - 1px)) {
margin: 20px 0 0 0; margin: 20px 0 0 0;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
.card; .card;
} }
margin: @padding-small-default 0px; margin: @padding-small-default 0px;
padding: 8px 15px 5px 15px; padding: 8px 8px 5px 8px;
width: 100%; width: 100%;
.result-header { .result-header {
display: flex; display: flex;
......
...@@ -28,15 +28,29 @@ ...@@ -28,15 +28,29 @@
</div> </div>
@if(sizeof($metager->getAvailableParameterFilter()) > 0) @if(sizeof($metager->getAvailableParameterFilter()) > 0)
<div id="options"> <div id="options">
<div id="toggle-box">
@if(sizeof($metager->getAvailableParameterFilter()) > 0)
<div class="option-toggle">
<label class="navigation-element" for="options-toggle">
<i class="fas fa-filter"></i> Filter&hellip;
</label>
</div>
@endif
@if(sizeof($metager->getParameterFilter()) > 0)
<div id="options-reset">
<a href="{{$metager->generateSearchLink($metager->getFokus())}}"><nobr>{{ trans('filter.reset') }}</nobr></a>
</div>
@endif
@if($metager->getTotalResultCount() > 0)
<div id="result-count">
~ {{$metager->getTotalResultCount()}} {{ trans('metaGer.results') }}
</div>
@endif
</div>
<input type="checkbox" id="options-toggle" @if(sizeof($metager->getParameterFilter()) > 0)checked @endif /> <input type="checkbox" id="options-toggle" @if(sizeof($metager->getParameterFilter()) > 0)checked @endif />
<div class="scrollbox"> <div class="scrollbox">
<div class="scrollfade-left"></div> <div class="scrollfade-left"></div>
<div id="options-box"> <div id="options-box">
@if(sizeof($metager->getParameterFilter()) > 0)
<div id="options-reset">
<a href="{{$metager->generateSearchLink($metager->getFokus())}}"><nobr>Filter zurücksetzen</nobr></a>
</div>
@endif
<div id="options-items"> <div id="options-items">
@foreach($metager->getAvailableParameterFilter() as $filterName => $filter) @foreach($metager->getAvailableParameterFilter() as $filterName => $filter)
<div class="option-selector"> <div class="option-selector">
......
...@@ -3,10 +3,3 @@ ...@@ -3,10 +3,3 @@
<a href="@if($metager->getFokus() === $name)#@else{!!$metager->generateSearchLink($name)!!}@endif" target="_self" tabindex="0">@lang($fokus->{"display-name"})</a> <a href="@if($metager->getFokus() === $name)#@else{!!$metager->generateSearchLink($name)!!}@endif" target="_self" tabindex="0">@lang($fokus->{"display-name"})</a>
</div> </div>
@endforeach @endforeach
@if(sizeof($metager->getAvailableParameterFilter()) > 0)
<div class="option-toggle">
<label class="navigation-element" for="options-toggle">
<i class="fas fa-filter"></i>
</label>
</div>
@endif
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