firefly-iii/app/Http/Controllers/SearchController.php

80 lines
1.9 KiB
PHP
Raw Normal View History

2016-05-20 01:57:45 -05:00
<?php
/**
* SearchController.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* 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.
*/
declare(strict_types=1);
2016-05-20 01:57:45 -05:00
namespace FireflyIII\Http\Controllers;
2015-02-27 04:09:23 -06:00
use FireflyIII\Support\Search\SearchInterface;
2016-11-06 07:52:31 -06:00
use Illuminate\Http\Request;
2017-07-15 10:19:12 -05:00
use Response;
use View;
2015-02-27 04:09:23 -06:00
/**
* Class SearchController
*
* @package FireflyIII\Http\Controllers
*/
2015-03-10 11:26:31 -05:00
class SearchController extends Controller
{
/**
* SearchController constructor.
*/
2016-01-08 11:29:47 -06:00
public function __construct()
{
2016-01-08 13:40:48 -06:00
parent::__construct();
2016-10-29 00:44:46 -05:00
$this->middleware(
function ($request, $next) {
View::share('mainTitleIcon', 'fa-search');
View::share('title', trans('firefly.search'));
return $next($request);
}
);
2016-01-08 11:29:47 -06:00
}
2015-02-27 04:09:23 -06:00
/**
2016-11-18 13:06:08 -06:00
* @param Request $request
2015-05-03 05:58:55 -05:00
* @param SearchInterface $searcher
*
* @return View
2015-02-27 04:09:23 -06:00
*/
2016-11-06 07:52:31 -06:00
public function index(Request $request, SearchInterface $searcher)
2015-02-27 04:09:23 -06:00
{
2017-09-15 23:52:53 -05:00
$fullQuery = strval($request->get('q'));
2017-07-15 09:41:07 -05:00
2017-07-15 10:19:12 -05: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 04:09:23 -06:00
}
2017-07-15 10:19:12 -05: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 04:09:23 -06:00
}