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

73 lines
2.1 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.
*/
2016-05-20 01:57:45 -05:00
declare(strict_types = 1);
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;
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
2016-01-08 11:29:47 -06:00
}
2015-02-27 04:09:23 -06:00
/**
* Results always come in the form of an array [results, count, fullCount]
2015-05-03 05:58:55 -05:00
*
* @param SearchInterface $searcher
*
* @return $this
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
{
2016-11-06 07:52:31 -06:00
$minSearchLen = 1;
$subTitle = null;
$query = null;
$result = [];
$title = trans('firefly.search');
2016-11-06 07:52:31 -06:00
$limit = 20;
$mainTitleIcon = 'fa-search';
2016-11-06 07:52:31 -06:00
// set limit for search:
$searcher->setLimit($limit);
if (!is_null($request->get('q')) && strlen($request->get('q')) >= $minSearchLen) {
$query = trim(strtolower($request->get('q')));
$words = explode(' ', $query);
$subTitle = trans('firefly.search_results_for', ['query' => $query]);
2016-02-05 12:25:17 -06:00
$transactions = $searcher->searchTransactions($words);
$accounts = $searcher->searchAccounts($words);
$categories = $searcher->searchCategories($words);
$budgets = $searcher->searchBudgets($words);
$tags = $searcher->searchTags($words);
2015-02-27 04:09:23 -06:00
$result = ['transactions' => $transactions, 'accounts' => $accounts, 'categories' => $categories, 'budgets' => $budgets, 'tags' => $tags];
}
2016-11-06 07:52:31 -06:00
return view('search.index', compact('title', 'subTitle', 'limit', 'mainTitleIcon', 'query', 'result'));
2015-02-27 04:09:23 -06:00
}
}