Improve search speed.

This commit is contained in:
James Cole
2019-02-27 19:08:09 +01:00
parent fe738fd321
commit 39321b320e
6 changed files with 90 additions and 127 deletions

View File

@@ -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
*

View File

@@ -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.
*