mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-08-26 12:16:07 +00:00
Applied styleci fixes and pluck improvement as per larastan
This commit is contained in:
parent
7405613f8d
commit
b3e1c7da73
@ -216,6 +216,7 @@ class SearchRunner
|
|||||||
/**
|
/**
|
||||||
* Create a select statement, with prepared bindings, for the given
|
* Create a select statement, with prepared bindings, for the given
|
||||||
* set of scored search terms.
|
* set of scored search terms.
|
||||||
|
*
|
||||||
* @return array{statement: string, bindings: string[]}
|
* @return array{statement: string, bindings: string[]}
|
||||||
*/
|
*/
|
||||||
protected function selectForScoredTerms(array $scoredTerms): array
|
protected function selectForScoredTerms(array $scoredTerms): array
|
||||||
@ -260,20 +261,27 @@ class SearchRunner
|
|||||||
$termQuery->selectRaw('COUNT(*) as count');
|
$termQuery->selectRaw('COUNT(*) as count');
|
||||||
$termQuery->groupByRaw($case, $whenBindings);
|
$termQuery->groupByRaw($case, $whenBindings);
|
||||||
|
|
||||||
$termCounts = $termQuery->get()->pluck('count', 'term')->toArray();
|
$termCounts = $termQuery->pluck('count', 'term')->toArray();
|
||||||
$adjusted = $this->rawTermCountsToAdjustments($termCounts);
|
$adjusted = $this->rawTermCountsToAdjustments($termCounts);
|
||||||
|
|
||||||
$this->termAdjustmentCache[$options] = $adjusted;
|
$this->termAdjustmentCache[$options] = $adjusted;
|
||||||
|
|
||||||
return $this->termAdjustmentCache[$options];
|
return $this->termAdjustmentCache[$options];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert counts of terms into a relative-count normalised multiplier.
|
* Convert counts of terms into a relative-count normalised multiplier.
|
||||||
|
*
|
||||||
* @param array<string, int> $termCounts
|
* @param array<string, int> $termCounts
|
||||||
|
*
|
||||||
* @return array<string, int>
|
* @return array<string, int>
|
||||||
*/
|
*/
|
||||||
protected function rawTermCountsToAdjustments(array $termCounts): array
|
protected function rawTermCountsToAdjustments(array $termCounts): array
|
||||||
{
|
{
|
||||||
|
if (empty($termCounts)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
$multipliers = [];
|
$multipliers = [];
|
||||||
$max = max(array_values($termCounts));
|
$max = max(array_values($termCounts));
|
||||||
|
|
||||||
@ -338,7 +346,8 @@ class SearchRunner
|
|||||||
try {
|
try {
|
||||||
$date = date_create($input);
|
$date = date_create($input);
|
||||||
$query->where('updated_at', '>=', $date);
|
$query->where('updated_at', '>=', $date);
|
||||||
} catch (\Exception $e) {}
|
} catch (\Exception $e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function filterUpdatedBefore(EloquentBuilder $query, Entity $model, $input): void
|
protected function filterUpdatedBefore(EloquentBuilder $query, Entity $model, $input): void
|
||||||
@ -346,7 +355,8 @@ class SearchRunner
|
|||||||
try {
|
try {
|
||||||
$date = date_create($input);
|
$date = date_create($input);
|
||||||
$query->where('updated_at', '<', $date);
|
$query->where('updated_at', '<', $date);
|
||||||
} catch (\Exception $e) {}
|
} catch (\Exception $e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function filterCreatedAfter(EloquentBuilder $query, Entity $model, $input): void
|
protected function filterCreatedAfter(EloquentBuilder $query, Entity $model, $input): void
|
||||||
@ -354,7 +364,8 @@ class SearchRunner
|
|||||||
try {
|
try {
|
||||||
$date = date_create($input);
|
$date = date_create($input);
|
||||||
$query->where('created_at', '>=', $date);
|
$query->where('created_at', '>=', $date);
|
||||||
} catch (\Exception $e) {}
|
} catch (\Exception $e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function filterCreatedBefore(EloquentBuilder $query, Entity $model, $input)
|
protected function filterCreatedBefore(EloquentBuilder $query, Entity $model, $input)
|
||||||
@ -362,7 +373,8 @@ class SearchRunner
|
|||||||
try {
|
try {
|
||||||
$date = date_create($input);
|
$date = date_create($input);
|
||||||
$query->where('created_at', '<', $date);
|
$query->where('created_at', '<', $date);
|
||||||
} catch (\Exception $e) {}
|
} catch (\Exception $e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function filterCreatedBy(EloquentBuilder $query, Entity $model, $input)
|
protected function filterCreatedBy(EloquentBuilder $query, Entity $model, $input)
|
||||||
|
Loading…
Reference in New Issue
Block a user