Skip to content

Firefly III: a personal finances manager

Fix issue with tag search.

James Cole949ca4f79e0f
diff --git a/app/Helpers/Collector/Extensions/MetaCollection.php b/app/Helpers/Collector/Extensions/MetaCollection.php
index bac8a27838..019981388d 100644
--- a/app/Helpers/Collector/Extensions/MetaCollection.php
+++ b/app/Helpers/Collector/Extensions/MetaCollection.php
@@ -681,13 +681,16 @@ trait MetaCollection
// this method adds a "postFilter" to the collector.
$list = $tags->pluck('tag')->toArray();
$list = array_map('strtolower', $list);
- $filter = static function (array $object) use ($list): bool {
+ $filter = static function (array $object) use ($list): bool | array {
+ $return = $object;
+ unset($return['transactions']);
+ $return['transactions'] = [];
Log::debug(sprintf('Now in setAllTags(%s) filter', implode(', ', $list)));
$expectedTagCount = count($list);
$foundTagCount = 0;
foreach ($object['transactions'] as $transaction) {
$transactionTagCount = count($transaction['tags']);
- app('log')->debug(sprintf('Transaction has %d tag(s)', $transactionTagCount));
+ app('log')->debug(sprintf('Transaction #%d has %d tag(s)', $transaction['transaction_journal_id'], $transactionTagCount));
if ($transactionTagCount < $expectedTagCount) {
app('log')->debug(sprintf('Transaction has %d tag(s), we expect %d tag(s), return false.', $transactionTagCount, $expectedTagCount));
@@ -698,13 +701,18 @@ trait MetaCollection
if (in_array(strtolower($tag['name']), $list, true)) {
app('log')->debug(sprintf('Transaction has tag "%s" so count++.', $tag['name']));
++$foundTagCount;
+ $return['transactions'][] = $transaction;
}
}
}
Log::debug(sprintf('Found %d tags, need at least %d.', $foundTagCount, $expectedTagCount));
// found at least the expected tags.
- return $foundTagCount >= $expectedTagCount;
+ $result = $foundTagCount >= $expectedTagCount;
+ if (true === $result) {
+ return $return;
+ }
+ return false;
};
$this->postFilters[] = $filter;
diff --git a/app/Helpers/Collector/GroupCollector.php b/app/Helpers/Collector/GroupCollector.php
index 7f8355fa81..955696d902 100644
--- a/app/Helpers/Collector/GroupCollector.php
+++ b/app/Helpers/Collector/GroupCollector.php
@@ -43,6 +43,7 @@ use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\Log;
/**
* Class GroupCollector
@@ -560,6 +561,7 @@ class GroupCollector implements GroupCollectorInterface
if (0 !== count($journalIds)) {
// make all integers.
$integerIDs = array_map('intval', $journalIds);
+ Log::debug(sprintf('GroupCollector: setJournalIds: %s', join(', ', $integerIDs)));
$this->query->whereIn('transaction_journals.id', $integerIDs);
}
@@ -948,7 +950,14 @@ class GroupCollector implements GroupCollectorInterface
// skip other filters, continue to next item.
continue;
}
- $nextCollection->push($item);
+ // if the result is a bool, use the unedited results.
+ if(true === $result) {
+ $nextCollection->push($item);
+ }
+ // if the result is an array, the filter has changed what's being returned.
+ if(is_array($result)) {
+ $nextCollection->push($result);
+ }
}
$currentCollection = $nextCollection;
app('log')->debug(sprintf('GroupCollector: postFilterCollection has %d transaction(s) left.', count($currentCollection)));
diff --git a/app/Support/Search/OperatorQuerySearch.php b/app/Support/Search/OperatorQuerySearch.php
index e8138faef8..e02349f863 100644
--- a/app/Support/Search/OperatorQuerySearch.php
+++ b/app/Support/Search/OperatorQuerySearch.php
@@ -156,8 +156,6 @@ class OperatorQuerySearch implements SearchInterface
foreach ($query1->getNodes() as $searchNode) {
$this->handleSearchNode($searchNode);
}
- $this->parseTagInstructions();
-
$this->collector->setSearchWords($this->words);
$this->collector->excludeSearchWords($this->prohibitedWords);
}
@@ -199,6 +197,7 @@ class OperatorQuerySearch implements SearchInterface
public function searchTransactions(): LengthAwarePaginator
{
+ $this->parseTagInstructions();
if (0 === count($this->getWords()) && 0 === count($this->getOperators())) {
return new LengthAwarePaginator([], 0, 5, 1);
}
diff --git a/app/TransactionRules/Engine/SearchRuleEngine.php b/app/TransactionRules/Engine/SearchRuleEngine.php
index fcd0383c93..4853c3ba09 100644
--- a/app/TransactionRules/Engine/SearchRuleEngine.php
+++ b/app/TransactionRules/Engine/SearchRuleEngine.php
@@ -183,7 +183,7 @@ class SearchRuleEngine implements RuleEngineInterface
continue;
}
- // if needs no context, value is different:
+ // if the trigger needs no context, value is different:
$needsContext = (bool) (config(sprintf('search.operators.%s.needs_context', $ruleTrigger->trigger_type)) ?? true);
if (false === $needsContext) {
app('log')->debug(sprintf('SearchRuleEngine:: add a rule trigger (no context): %s:true', $ruleTrigger->trigger_type));
@@ -211,7 +211,7 @@ class SearchRuleEngine implements RuleEngineInterface
$searchEngine->setPage(1);
$searchEngine->setLimit(31337);
$searchEngine->setDate($date);
-
+ app('log')->debug('Search array', $searchArray);
foreach ($searchArray as $type => $searches) {
foreach ($searches as $value) {
$query = sprintf('%s:%s', $type, $value);