mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
- 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
40 lines
906 B
PHP
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;
|
|
}
|
|
}
|