mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 03:43:07 +00:00
Some search fixes.
This commit is contained in:
@@ -46,7 +46,7 @@ class SearchController extends Controller
|
||||
$this->middleware(
|
||||
static function ($request, $next) {
|
||||
app('view')->share('mainTitleIcon', 'fa-search');
|
||||
app('view')->share('title', (string) trans('firefly.search'));
|
||||
app('view')->share('title', (string)trans('firefly.search'));
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
@@ -65,14 +65,13 @@ class SearchController extends Controller
|
||||
{
|
||||
// search params:
|
||||
$fullQuery = $request->get('search');
|
||||
if(is_array($request->get('search'))) {
|
||||
if (is_array($request->get('search'))) {
|
||||
$fullQuery = '';
|
||||
}
|
||||
$fullQuery = (string) $fullQuery;
|
||||
$page = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page');
|
||||
$ruleId = (int) $request->get('rule');
|
||||
$rule = null;
|
||||
$ruleChanged = false;
|
||||
$fullQuery = (string)$fullQuery;
|
||||
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
|
||||
$ruleId = (int)$request->get('rule');
|
||||
$ruleChanged = false;
|
||||
|
||||
// find rule, check if query is different, offer to update.
|
||||
$ruleRepository = app(RuleRepositoryInterface::class);
|
||||
@@ -87,12 +86,12 @@ class SearchController extends Controller
|
||||
$searcher->parseQuery($fullQuery);
|
||||
|
||||
// words from query and operators:
|
||||
$query = $searcher->getWordsAsString();
|
||||
$operators = $searcher->getOperators();
|
||||
$query = $searcher->getWordsAsString();
|
||||
$operators = $searcher->getOperators();
|
||||
$invalidOperators = $searcher->getInvalidOperators();
|
||||
$subTitle = (string)trans('breadcrumbs.search_result', ['query' => $fullQuery]);
|
||||
|
||||
$subTitle = (string) trans('breadcrumbs.search_result', ['query' => $fullQuery]);
|
||||
|
||||
return prefixView('search.index', compact('query', 'operators', 'page', 'rule', 'fullQuery', 'subTitle', 'ruleId', 'ruleChanged'));
|
||||
return prefixView('search.index', compact('query', 'operators', 'page', 'rule', 'fullQuery', 'subTitle', 'ruleId', 'ruleChanged', 'invalidOperators'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,8 +104,8 @@ class SearchController extends Controller
|
||||
*/
|
||||
public function search(Request $request, SearchInterface $searcher): JsonResponse
|
||||
{
|
||||
$fullQuery = (string) $request->get('query');
|
||||
$page = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page');
|
||||
$fullQuery = (string)$request->get('query');
|
||||
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
|
||||
|
||||
$searcher->parseQuery($fullQuery);
|
||||
|
||||
@@ -125,6 +124,7 @@ class SearchController extends Controller
|
||||
Log::error(sprintf('Cannot render search.search: %s', $e->getMessage()));
|
||||
$html = 'Could not render view.';
|
||||
}
|
||||
|
||||
return response()->json(['count' => $groups->count(), 'html' => $html]);
|
||||
}
|
||||
}
|
||||
|
@@ -36,7 +36,6 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use FireflyIII\Repositories\TransactionType\TransactionTypeRepositoryInterface;
|
||||
use FireflyIII\Support\ParseDateString;
|
||||
use FireflyIII\User;
|
||||
use Gdbots\QueryParser\Node\Date;
|
||||
@@ -62,25 +61,23 @@ use Log;
|
||||
*/
|
||||
class OperatorQuerySearch implements SearchInterface
|
||||
{
|
||||
private AccountRepositoryInterface $accountRepository;
|
||||
private BillRepositoryInterface $billRepository;
|
||||
private BudgetRepositoryInterface $budgetRepository;
|
||||
private CategoryRepositoryInterface $categoryRepository;
|
||||
private GroupCollectorInterface $collector;
|
||||
private CurrencyRepositoryInterface $currencyRepository;
|
||||
private Carbon $date;
|
||||
private int $limit;
|
||||
private Collection $modifiers;
|
||||
private Collection $operators;
|
||||
private string $originalQuery;
|
||||
private int $page;
|
||||
private ParsedQuery $query;
|
||||
private float $startTime;
|
||||
private TagRepositoryInterface $tagRepository;
|
||||
private TransactionTypeRepositoryInterface $typeRepository; // obsolete
|
||||
private User $user;
|
||||
private array $validOperators;
|
||||
private array $words;
|
||||
private AccountRepositoryInterface $accountRepository;
|
||||
private BillRepositoryInterface $billRepository;
|
||||
private BudgetRepositoryInterface $budgetRepository;
|
||||
private CategoryRepositoryInterface $categoryRepository;
|
||||
private GroupCollectorInterface $collector;
|
||||
private CurrencyRepositoryInterface $currencyRepository;
|
||||
private Carbon $date;
|
||||
private int $limit;
|
||||
private Collection $operators;
|
||||
private int $page;
|
||||
private ParsedQuery $query;
|
||||
private float $startTime;
|
||||
private TagRepositoryInterface $tagRepository;
|
||||
private User $user;
|
||||
private array $validOperators;
|
||||
private array $words;
|
||||
private array $invalidOperators;
|
||||
|
||||
/**
|
||||
* OperatorQuerySearch constructor.
|
||||
@@ -90,12 +87,11 @@ class OperatorQuerySearch implements SearchInterface
|
||||
public function __construct()
|
||||
{
|
||||
Log::debug('Constructed OperatorQuerySearch');
|
||||
$this->modifiers = new Collection; // obsolete
|
||||
$this->operators = new Collection;
|
||||
$this->page = 1;
|
||||
$this->words = [];
|
||||
$this->invalidOperators = [];
|
||||
$this->limit = 25;
|
||||
$this->originalQuery = '';
|
||||
$this->date = today(config('app.timezone'));
|
||||
$this->validOperators = array_keys(config('firefly.search.operators'));
|
||||
$this->startTime = microtime(true);
|
||||
@@ -105,7 +101,6 @@ class OperatorQuerySearch implements SearchInterface
|
||||
$this->billRepository = app(BillRepositoryInterface::class);
|
||||
$this->tagRepository = app(TagRepositoryInterface::class);
|
||||
$this->currencyRepository = app(CurrencyRepositoryInterface::class);
|
||||
$this->typeRepository = app(TransactionTypeRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,9 +146,8 @@ class OperatorQuerySearch implements SearchInterface
|
||||
public function parseQuery(string $query)
|
||||
{
|
||||
Log::debug(sprintf('Now in parseQuery(%s)', $query));
|
||||
$parser = new QueryParser();
|
||||
$this->query = $parser->parse($query);
|
||||
$this->originalQuery = $query;
|
||||
$parser = new QueryParser();
|
||||
$this->query = $parser->parse($query);
|
||||
|
||||
Log::debug(sprintf('Found %d node(s)', count($this->query->getNodes())));
|
||||
foreach ($this->query->getNodes() as $searchNode) {
|
||||
@@ -202,6 +196,14 @@ class OperatorQuerySearch implements SearchInterface
|
||||
$this->collector->setLimit($this->limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getInvalidOperators(): array
|
||||
{
|
||||
return $this->invalidOperators;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @codeCoverageIgnore
|
||||
@@ -277,6 +279,11 @@ class OperatorQuerySearch implements SearchInterface
|
||||
'value' => (string)$value,
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$this->invalidOperators[] = [
|
||||
'type' => $operator,
|
||||
'value' => (string)$value,
|
||||
];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@@ -42,6 +42,11 @@ interface SearchInterface
|
||||
*/
|
||||
public function getOperators(): Collection;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getInvalidOperators(): array;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
Reference in New Issue
Block a user