Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/Search/SearchQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class SearchQuery implements SortableQuery, CollapsibleQuery, HighlightingQuery
protected ?int $from = null;
protected array $fields = [];
protected array $include = [];
protected ?array $pinnedIds = null;
protected array $exclude = [];
protected ?string $searchType = null;

Expand Down Expand Up @@ -144,17 +145,24 @@ protected function execute(
?int $from = null,
bool $totals = false,
bool $source = true,
?Cursor $cursor = null
?Cursor $cursor = null,
): array|Promise {
$dsl = [
'size' => $size,
'from' => $from,
'query' => $this->boolQuery->toDSL(),
'query' => [],
'track_total_hits' => $totals,
'_source' => $this->sourceToDSL($source),
'fields' => $source && $this->fields ? $this->fields : null,
];

if ($this->pinnedIds) {
$dsl['query']['pinned']['ids'] = $this->pinnedIds;
$dsl['query']['pinned']['organic'] = $this->boolQuery->toDSL();
} else {
$dsl['query'] = $this->boolQuery->toDSL();
}

$sorts ??= $this->sorts;
if (!$sorts->isEmpty()) {
$dsl['sort'] = $sorts->toDSL();
Expand Down Expand Up @@ -245,6 +253,13 @@ public function setPostFilter(BoolQueryBuilder $boolQueryBuilder): static
return $this;
}

public function pinned(array $ids): static
{
$this->pinnedIds = $ids;

return $this;
}

public function addAggregations(Aggregation $aggregation): static
{
$this->aggregations ??= new AggregationCollection();
Expand Down
Loading