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

74 lines
2.1 KiB
PHP
Raw Normal View History

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