mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-11-12 17:18:48 +01:00
fix(api): load aggregate fields for search builder (#587)
This commit is contained in:
1 parent
4c33114f38
commit
ce794f40ff
1 file changed
+8
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Scout\Elasticsearch;
|
||||
|
||||
use App\Concerns\Actions\Http\Api\AggregatesFields;
|
||||
use App\Concerns\Actions\Http\Api\ConstrainsEagerLoads;
|
||||
use App\Enums\Http\Api\Paging\PaginationStrategy;
|
||||
use App\Http\Api\Query\Query;
|
||||
@@ -19,6 +20,7 @@ use Elastic\ScoutDriverPlus\Builders\BoolQueryBuilder;
|
||||
use Elastic\ScoutDriverPlus\Exceptions\QueryBuilderValidationException;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -28,6 +30,7 @@ use Illuminate\Support\Str;
|
||||
*/
|
||||
class Elasticsearch extends Search
|
||||
{
|
||||
use AggregatesFields;
|
||||
use ConstrainsEagerLoads;
|
||||
|
||||
/**
|
||||
@@ -93,6 +96,11 @@ class Elasticsearch extends Search
|
||||
// initialize builder for matches
|
||||
$builder = $elasticQuery->build($query->getSearchCriteria());
|
||||
|
||||
// load aggregate fields
|
||||
$builder->refineModels(function (Builder $searchModelBuilder) use ($query, $schema) {
|
||||
$this->withAggregates($searchModelBuilder, $query, $schema);
|
||||
});
|
||||
|
||||
// eager load relations with constraints
|
||||
$builder = $builder->load($this->constrainEagerLoads($query, $schema));
|
||||
|
||||
|
||||
Reference in new issue
Block a user