jikan-rest/app/Filters/WhereClause.php
pushrbx 4aa3c4c617 fixed #332
- added logic to forward `order_by` parameter to the search engine
- modified mongodb query when no search engine is present to use "textMatchScore" name instead of "score" for text match scores -- the text score projection was shadowing the "score" attribute
2023-05-21 11:14:34 +01:00

40 lines
906 B
PHP

<?php
namespace App\Filters;
use Illuminate\Database\Eloquent\Builder;
class WhereClause extends BaseClause
{
protected function apply($query): Builder
{
$method = is_array($this->values) ? 'orWhere' : 'andWhere';
return $this->{$method}($query, $this->filter, $this->values);
}
protected function validate($value): bool
{
return !in_array(null, (array)$value);
}
private function orWhere($query, $filter, $values): Builder
{
$query->where(function($query) use($values, $filter) {
foreach((array)$values as $value) {
$query->orWhere($filter, $value);
}
});
return $query;
}
private function andWhere($query, $filter, $values): Builder
{
foreach((array)$values as $value) {
$query->where($filter, $value);
}
return $query;
}
}