Commit e93616ea authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Merge branch '454-zitatsuche-uberfuhren' into 'development'

Zitatsuche funktioniert wieder korrekt

Closes #454

See merge request !763
parents 4148ebd1 dec3ed4b
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ZitatController extends Controller
public function zitatSuche(Request $request)
$validResults = [];
if ($request->has("q")) {
# The user searched for something
$fileName = storage_path() . "/app/public/zitate.txt";
$fileContent = file_get_contents($fileName);
# Die Suchworte sind UND verknüpft, müssen aber nicht als gesamtes Wort vorkommen
$all = explode(PHP_EOL, $fileContent);
$words = preg_split("/\s+/", $request->input('q'));
# Loop through all
foreach ($all as $zitat) {
$valid = true;
# A Result isn't valid when it doesn't Contain every search word
foreach ($words as $word) {
if (stripos($zitat, $word) === false) {
$valid = false;
if ($valid) {
# This Result is valid. We'll add it Sorted by author
if (preg_match("/^\"([^\"]+)\"\s(.*)$/", $zitat, $matches)) {
$quote = $matches[1];
$author = $matches[2];
if (isset($validResults[$author])) {
$validResults[$author][] = $quote;
} else {
$validResults[$author] = [$quote];
return view('zitatsuche')
->with('title', 'Zitatsuche MetaGer')
->with('navbarFocus', 'dienste')
->with('results', $validResults)
->with('q', $request->input('q', ''));
return [
'head.1' => 'MetaGer - Zitatsuche',
'p.1' => 'In dem unten stehenden Textfeld können Sie in unserer Datenbank nach Zitaten oder Autoren suchen.',
......@@ -141,7 +141,7 @@
<a href="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), "/widget/") }}">{{ trans('staticPages.nav10') }}</a>
<a href="" >{{ trans('staticPages.nav22') }}</a>
<a href="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), "/zitat-suche/") }}" >{{ trans('staticPages.nav22') }}</a>
<a href="" >{{ trans('staticPages.nav11') }}</a>
@section('title', $title )
<h1>{{ trans('zitatsuche.head.1') }}</h1>
<p>{{ trans('zitatsuche.p.1') }}</p>
<form id="searchForm" class="form-inline" accept-charset="UTF-8">
<div class="form-group">
<label class="sr-only" for="q">Suchworte eingeben</label>
<div class="input-group">
<input type="text" class="form-control" id="q" name="q" placeholder="Suchworte" value="{{ $q }}">
<div class="input-group-addon"><button type="submit"><span class="glyphicon glyphicon-search"></span></button></div>
@if($q !== "")
<hr />
<h3>Ergebnisse für die Suche "{{$q}}":</h3>
@foreach($results as $author => $quotes)
<ul class="list-unstyled">
@foreach($quotes as $quote)
<li><quote>"{{ $quote }}"</quote></li>
......@@ -127,6 +127,8 @@ Route::group(
->with('navbarFocus', 'dienste');
Route::get('zitat-suche', 'ZitatController@zitatSuche');
Route::group(['middleware' => ['referer.check'], 'prefix' => 'admin'], function () {
Route::get('/', 'AdminInterface@index');
Route::get('count', 'AdminInterface@count');
This source diff could not be displayed because it is too large. You can view the blob instead.
Supports Markdown
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