2014-07-29 13:30:50 -05:00
|
|
|
<?php
|
2014-09-22 00:25:14 -05:00
|
|
|
|
2014-08-10 08:01:46 -05:00
|
|
|
/**
|
|
|
|
* Class SearchController
|
|
|
|
*/
|
2014-08-09 06:50:54 -05:00
|
|
|
class SearchController extends BaseController
|
2014-07-29 13:30:50 -05:00
|
|
|
{
|
2014-08-10 08:01:46 -05:00
|
|
|
/**
|
2014-09-22 00:25:14 -05:00
|
|
|
* Results always come in the form of an array [results, count, fullCount]
|
2014-08-10 08:01:46 -05:00
|
|
|
*/
|
2014-07-29 13:30:50 -05:00
|
|
|
public function index()
|
|
|
|
{
|
2014-11-13 14:11:00 -06:00
|
|
|
|
|
|
|
/** @var \FireflyIII\Search\Search $searcher */
|
|
|
|
$searcher = App::make('FireflyIII\Search\Search');
|
|
|
|
|
2014-09-22 00:25:14 -05:00
|
|
|
$subTitle = null;
|
2014-09-26 23:06:31 -05:00
|
|
|
$rawQuery = null;
|
2014-11-12 15:36:02 -06:00
|
|
|
$result = [];
|
2014-12-30 11:44:49 -06:00
|
|
|
if (!is_null(Input::get('q')) && strlen(Input::get('q')) > 0) {
|
2014-09-22 00:25:14 -05:00
|
|
|
$rawQuery = trim(Input::get('q'));
|
|
|
|
$words = explode(' ', $rawQuery);
|
|
|
|
$subTitle = 'Results for "' . e($rawQuery) . '"';
|
|
|
|
|
2014-11-13 14:11:00 -06:00
|
|
|
$transactions = $searcher->searchTransactions($words);
|
|
|
|
$accounts = $searcher->searchAccounts($words);
|
|
|
|
$categories = $searcher->searchCategories($words);
|
|
|
|
$budgets = $searcher->searchBudgets($words);
|
|
|
|
$tags = $searcher->searchTags($words);
|
2014-11-12 15:36:02 -06:00
|
|
|
$result = ['transactions' => $transactions, 'accounts' => $accounts, 'categories' => $categories, 'budgets' => $budgets, 'tags' => $tags];
|
2014-09-22 00:25:14 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return View::make('search.index')->with('title', 'Search')->with('subTitle', $subTitle)->with(
|
|
|
|
'mainTitleIcon', 'fa-search'
|
2014-11-12 15:36:02 -06:00
|
|
|
)->with('query', $rawQuery)->with('result', $result);
|
2014-07-29 13:30:50 -05:00
|
|
|
}
|
2015-01-01 23:16:49 -06:00
|
|
|
}
|