Skip to content
Snippets Groups Projects
Commit 978a08bb authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

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

parent d7a62236
No related branches found
No related tags found
1 merge request!1408Development
...@@ -14,6 +14,8 @@ use Predis\Connection\ConnectionException; ...@@ -14,6 +14,8 @@ use Predis\Connection\ConnectionException;
class MetaGer class MetaGer
{ {
# Einstellungen für die Suche # Einstellungen für die Suche
public $alteredQuery = "";
public $alterationOverrideQuery = "";
protected $fokus; protected $fokus;
protected $eingabe; protected $eingabe;
protected $q; protected $q;
...@@ -33,6 +35,7 @@ class MetaGer ...@@ -33,6 +35,7 @@ class MetaGer
protected $queryFilter = []; protected $queryFilter = [];
protected $parameterFilter = []; protected $parameterFilter = [];
protected $ads = []; protected $ads = [];
protected $infos = [];
protected $warnings = []; protected $warnings = [];
protected $errors = []; protected $errors = [];
protected $addedHosts = []; protected $addedHosts = [];
...@@ -461,7 +464,20 @@ class MetaGer ...@@ -461,7 +464,20 @@ class MetaGer
if (empty($this->sumaFile->foki->{$this->fokus})) { if (empty($this->sumaFile->foki->{$this->fokus})) {
$this->fokus = "web"; $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 # Check if this engine is disabled and can't be used
$disabled = empty($this->sumaFile->sumas->{$suma}->disabled) ? false : $this->sumaFile->sumas->{$suma}->disabled; $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"}; $autoDisabled = empty($this->sumaFile->sumas->{$suma}->{"auto-disabled"}) ? false : $this->sumaFile->sumas->{$suma}->{"auto-disabled"};
...@@ -767,6 +783,10 @@ class MetaGer ...@@ -767,6 +783,10 @@ class MetaGer
if (!empty($engine->totalResults) && $engine->totalResults > $this->totalResults) { if (!empty($engine->totalResults) && $engine->totalResults > $this->totalResults) {
$this->totalResults = $engine->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 ...@@ -1319,6 +1339,17 @@ class MetaGer
return $link; 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() public function generateQuicktipLink()
{ {
$link = action('MetaGerSearch@quicktips'); $link = action('MetaGerSearch@quicktips');
...@@ -1548,6 +1579,11 @@ class MetaGer ...@@ -1548,6 +1579,11 @@ class MetaGer
return $this->startCount; return $this->startCount;
} }
public function getInfos()
{
return $this->infos;
}
public function getRedisResultWaitingKey() public function getRedisResultWaitingKey()
{ {
return $this->redisResultWaitingKey; return $this->redisResultWaitingKey;
......
...@@ -19,6 +19,13 @@ class Bing extends Searchengine ...@@ -19,6 +19,13 @@ class Bing extends Searchengine
try { try {
$results = json_decode($result); $results = json_decode($result);
$this->totalResults = $results->webPages->totalEstimatedMatches; $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; $results = $results->webPages->value;
foreach ($results as $result) { foreach ($results as $result) {
......
...@@ -364,6 +364,23 @@ a { ...@@ -364,6 +364,23 @@ a {
.alert { .alert {
margin-bottom: @padding-small-default; 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 { #additions-container {
grid-area: additions; 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"> <div id="results">
@include('parts.alteration')
@if($mobile) @if($mobile)
@include('layouts.ad', ['ad' => $metager->popAd()]) @include('layouts.ad', ['ad' => $metager->popAd()])
@else @else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment