Commit 978a08bb authored by Dominik Hebeler's avatar Dominik Hebeler

Added query alteration to MetaGer and disabled yahoo for ad-free searches

parent d7a62236
......@@ -14,6 +14,8 @@ use Predis\Connection\ConnectionException;
class MetaGer
{
# Einstellungen für die Suche
public $alteredQuery = "";
public $alterationOverrideQuery = "";
protected $fokus;
protected $eingabe;
protected $q;
......@@ -33,6 +35,7 @@ class MetaGer
protected $queryFilter = [];
protected $parameterFilter = [];
protected $ads = [];
protected $infos = [];
protected $warnings = [];
protected $errors = [];
protected $addedHosts = [];
......@@ -461,7 +464,20 @@ class MetaGer
if (empty($this->sumaFile->foki->{$this->fokus})) {
$this->fokus = "web";
}
foreach ($this->sumaFile->foki->{$this->fokus}->sumas as $suma) {
$sumaList = $this->sumaFile->foki->{$this->fokus}->sumas;
# If the user is authorized to use adfree search we won't activate yahoo or yahoo-ads
if ($this->apiAuthorized && ($key = array_search("yahoo", $sumaList)) !== false) {
unset($sumaList[$key]);
if ($this->fokus === "web") {
$this->sumaFile->sumas->{"bing"}->{"filter-opt-in"} = false;
}
} elseif ($this->apiAuthorized && ($key = array_search("yahoo-ads", $sumaList)) !== false) {
unset($sumaList[$key]);
}
foreach ($sumaList as $suma) {
# Check if this engine is disabled and can't be used
$disabled = empty($this->sumaFile->sumas->{$suma}->disabled) ? false : $this->sumaFile->sumas->{$suma}->disabled;
$autoDisabled = empty($this->sumaFile->sumas->{$suma}->{"auto-disabled"}) ? false : $this->sumaFile->sumas->{$suma}->{"auto-disabled"};
......@@ -767,6 +783,10 @@ class MetaGer
if (!empty($engine->totalResults) && $engine->totalResults > $this->totalResults) {
$this->totalResults = $engine->totalResults;
}
if (!empty($engine->alteredQuery) && !empty($engine->alterationOverrideQuery)) {
$this->alteredQuery = $engine->alteredQuery;
$this->alterationOverrideQuery = $engine->alterationOverrideQuery;
}
}
}
......@@ -1319,6 +1339,17 @@ class MetaGer
return $link;
}
public function generateEingabeLink($eingabe)
{
$except = ['page', 'next', 'out', 'eingabe'];
$requestData = $this->request->except($except);
$requestData['eingabe'] = $eingabe;
$link = action('MetaGerSearch@search', $requestData);
return $link;
}
public function generateQuicktipLink()
{
$link = action('MetaGerSearch@quicktips');
......@@ -1548,6 +1579,11 @@ class MetaGer
return $this->startCount;
}
public function getInfos()
{
return $this->infos;
}
public function getRedisResultWaitingKey()
{
return $this->redisResultWaitingKey;
......
......@@ -19,6 +19,13 @@ class Bing extends Searchengine
try {
$results = json_decode($result);
$this->totalResults = $results->webPages->totalEstimatedMatches;
# Check if the query got altered
if (!empty($results->{"queryContext"}) && !empty($results->{"queryContext"}->{"alteredQuery"}) && !empty($results->{"queryContext"}->{"alterationOverrideQuery"})) {
$this->alteredQuery = $results->{"queryContext"}->{"alteredQuery"};
$this->alterationOverrideQuery = $results->{"queryContext"}->{"alterationOverrideQuery"};
}
$results = $results->webPages->value;
foreach ($results as $result) {
......
......@@ -364,6 +364,23 @@ a {
.alert {
margin-bottom: @padding-small-default;
}
#results .alteration {
margin: (@padding-small-default * 2) 0px;
margin-top: 0;
padding: 0px 8px;
font-weight: 400;
a i {
font-size: 80%;
}
.original {
font-size: 80%;
}
@media(max-width: @screen-mobile){
.card;
margin: @padding-small-default 0px;
margin-top: 0;
}
}
}
#additions-container {
grid-area: additions;
......
{{-- Show all infos --}}
@if(!empty($metager->alteredQuery) && !empty($metager->alterationOverrideQuery))
<div class="alteration">
<div>Enthält Ergebnisse für <a href="{{ $metager->generateEingabeLink($metager->alteredQuery) }}">{{ $metager->alteredQuery }} <i class="fa fa-search"></i></a></div>
<div class="original">Stattdessen nach <a href="{{ $metager->generateEingabeLink($metager->alterationOverrideQuery) }}">{{$metager->getEingabe() }} <i class="fa fa-search"></i></a> suchen</div>
</div>
@endif
<div id="results">
@include('parts.alteration')
@if($mobile)
@include('layouts.ad', ['ad' => $metager->popAd()])
@else
......
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