Fix search

This commit is contained in:
James Cole
2019-08-02 05:32:30 +02:00
parent fc70afa3ea
commit ac903b88ba
4 changed files with 15 additions and 16 deletions

View File

@@ -22,11 +22,9 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
use FireflyIII\Support\CacheProperties;
use FireflyIII\Support\Search\SearchInterface;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Log;
use Throwable;
@@ -62,7 +60,7 @@ class SearchController extends Controller
*/
public function index(Request $request, SearchInterface $searcher)
{
$fullQuery = (string)$request->get('q');
$fullQuery = (string)$request->get('search');
// parse search terms:
$searcher->parseQuery($fullQuery);
@@ -70,7 +68,10 @@ class SearchController extends Controller
$modifiers = $searcher->getModifiers();
$subTitle = (string)trans('breadcrumbs.search_result', ['query' => $query]);
return view('search.index', compact('query','modifiers', 'fullQuery', 'subTitle'));
return view(
'search.index',
compact('query', 'modifiers', 'fullQuery', 'subTitle')
);
}
/**
@@ -83,15 +84,15 @@ class SearchController extends Controller
*/
public function search(Request $request, SearchInterface $searcher): JsonResponse
{
$fullQuery = (string)$request->get('search');
$fullQuery = (string)$request->get('query');
$searcher->parseQuery($fullQuery);
$searcher->setLimit((int)config('firefly.search_result_limit'));
$transactions = $searcher->searchTransactions();
$groups = $searcher->searchTransactions();
$searchTime = $searcher->searchTime(); // in seconds
try {
$html = view('search.search', compact('transactions','searchTime'))->render();
$html = view('search.search', compact('groups','searchTime'))->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::error(sprintf('Cannot render search.search: %s', $e->getMessage()));
@@ -100,6 +101,6 @@ class SearchController extends Controller
// @codeCoverageIgnoreEnd
return response()->json(['count' => $transactions->count(), 'html' => $html]);
return response()->json(['count' => $groups->count(), 'html' => $html]);
}
}

View File

@@ -168,13 +168,12 @@ class Search implements SearchInterface
$collector->setLimit($pageSize)->setPage($page)->withAccountInformation();
$collector->withCategoryInformation()->withBudgetInformation();
$collector->setSearchWords($this->words);
// Most modifiers can be applied to the collector directly.
$collector = $this->applyModifiers($collector);
return $collector->getPaginatedTransactions();
return $collector->getPaginatedGroups();
}

View File

@@ -104,9 +104,9 @@
<section class="sidebar">
<form action="{{ route('search.index') }}" method="get" class="sidebar-form">
<div class="input-group">
<input autocomplete="off" type="text" name="q" class="form-control" placeholder="{{ 'searchPlaceholder'|_ }}" value="{{ query }}"/>
<input autocomplete="off" type="text" name="search" class="form-control" placeholder="{{ 'searchPlaceholder'|_ }}" value="{{ query }}"/>
<span class="input-group-btn">
<button type='submit' name='search' id='search-btn' class="btn btn-flat"><i class="fa fa-search"></i></button>
<button type='submit' name='go' id='search-btn' class="btn btn-flat"><i class="fa fa-search"></i></button>
</span>
</div>
</form>

View File

@@ -3,5 +3,4 @@
{{ trans('firefly.search_found_transactions', {count: transactions.count, time: searchTime}) }}
</p>
{# TODO REPLACE ME#}
<h1 style="color:red;">REPLACE ME</h1>
{% include 'list.groups' %}