2016-05-20 08:57:45 +02:00
|
|
|
<?php
|
2016-05-20 12:27:31 +02:00
|
|
|
/**
|
|
|
|
* SearchController.php
|
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
|
|
*
|
2016-10-05 06:52:15 +02:00
|
|
|
* This software may be modified and distributed under the terms of the
|
|
|
|
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
|
|
|
*
|
|
|
|
* See the LICENSE file for details.
|
2016-05-20 12:27:31 +02:00
|
|
|
*/
|
|
|
|
|
2017-04-09 07:44:22 +02:00
|
|
|
declare(strict_types=1);
|
2016-05-20 08:57:45 +02:00
|
|
|
|
|
|
|
namespace FireflyIII\Http\Controllers;
|
2015-02-27 11:09:23 +01:00
|
|
|
|
|
|
|
use FireflyIII\Support\Search\SearchInterface;
|
2016-11-06 14:52:31 +01:00
|
|
|
use Illuminate\Http\Request;
|
2017-07-15 17:19:12 +02:00
|
|
|
use Response;
|
2017-02-18 20:10:03 +01:00
|
|
|
use View;
|
2015-02-27 11:09:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class SearchController
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Http\Controllers
|
|
|
|
*/
|
2015-03-10 17:26:31 +01:00
|
|
|
class SearchController extends Controller
|
|
|
|
{
|
2016-01-09 08:20:55 +01:00
|
|
|
/**
|
|
|
|
* SearchController constructor.
|
|
|
|
*/
|
2016-01-08 18:29:47 +01:00
|
|
|
public function __construct()
|
|
|
|
{
|
2016-01-08 20:40:48 +01:00
|
|
|
parent::__construct();
|
2016-10-29 07:44:46 +02:00
|
|
|
|
2017-02-18 20:10:03 +01:00
|
|
|
$this->middleware(
|
|
|
|
function ($request, $next) {
|
|
|
|
View::share('mainTitleIcon', 'fa-search');
|
|
|
|
View::share('title', trans('firefly.search'));
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2016-01-08 18:29:47 +01:00
|
|
|
}
|
|
|
|
|
2015-02-27 11:09:23 +01:00
|
|
|
/**
|
2016-11-18 20:06:08 +01:00
|
|
|
* @param Request $request
|
2015-05-03 12:58:55 +02:00
|
|
|
* @param SearchInterface $searcher
|
|
|
|
*
|
2017-02-18 20:10:03 +01:00
|
|
|
* @return View
|
2015-02-27 11:09:23 +01:00
|
|
|
*/
|
2016-11-06 14:52:31 +01:00
|
|
|
public function index(Request $request, SearchInterface $searcher)
|
2015-02-27 11:09:23 +01:00
|
|
|
{
|
2017-07-15 17:19:12 +02:00
|
|
|
$fullQuery = $request->get('q');
|
2017-07-15 16:41:07 +02:00
|
|
|
|
2017-07-15 17:19:12 +02:00
|
|
|
// parse search terms:
|
|
|
|
$searcher->parseQuery($fullQuery);
|
|
|
|
$query = $searcher->getWordsAsString();
|
|
|
|
$subTitle = trans('breadcrumbs.search_result', ['query' => $query]);
|
|
|
|
|
|
|
|
return view('search.index', compact('query', 'fullQuery', 'subTitle'));
|
2015-02-27 11:09:23 +01:00
|
|
|
}
|
|
|
|
|
2017-07-15 17:19:12 +02:00
|
|
|
public function search(Request $request, SearchInterface $searcher)
|
|
|
|
{
|
|
|
|
$fullQuery = $request->get('query');
|
|
|
|
|
|
|
|
// parse search terms:
|
|
|
|
$searcher->parseQuery($fullQuery);
|
|
|
|
$searcher->setLimit(20);
|
|
|
|
$transactions = $searcher->searchTransactions();
|
|
|
|
$html = view('search.search', compact('transactions'))->render();
|
|
|
|
|
|
|
|
return Response::json(['count' => $transactions->count(), 'html' => $html]);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-02-27 11:09:23 +01:00
|
|
|
}
|