mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Improve search speed.
This commit is contained in:
@@ -651,6 +651,40 @@ class TransactionCollector implements TransactionCollectorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for words in descriptions.
|
||||
*
|
||||
* @param array $array
|
||||
*
|
||||
* @return TransactionCollectorInterface
|
||||
*/
|
||||
public function setSearchWords(array $array): TransactionCollectorInterface
|
||||
{
|
||||
// 'transaction_journals.description',
|
||||
$this->query->where(
|
||||
function (EloquentBuilder $q) use ($array) {
|
||||
$q->where(
|
||||
function (EloquentBuilder $q1) use ($array) {
|
||||
foreach ($array as $word) {
|
||||
$keyword = sprintf('%%%s%%', $word);
|
||||
$q1->where('transaction_journals.description', 'LIKE', $keyword);
|
||||
}
|
||||
}
|
||||
);
|
||||
$q->orWhere(
|
||||
function (EloquentBuilder $q2) use ($array) {
|
||||
foreach ($array as $word) {
|
||||
$keyword = sprintf('%%%s%%', $word);
|
||||
$q2->where('transactions.description', 'LIKE', $keyword);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
*
|
||||
|
@@ -272,6 +272,15 @@ interface TransactionCollectorInterface
|
||||
*/
|
||||
public function setRange(Carbon $start, Carbon $end): TransactionCollectorInterface;
|
||||
|
||||
/**
|
||||
* Search for words in descriptions.
|
||||
*
|
||||
* @param array $array
|
||||
*
|
||||
* @return TransactionCollectorInterface
|
||||
*/
|
||||
public function setSearchWords(array $array): TransactionCollectorInterface;
|
||||
|
||||
/**
|
||||
* Set the tag to collect from.
|
||||
*
|
||||
|
Reference in New Issue
Block a user