Skip to content

Commit e9509bc

Browse files
authored
Merge pull request #106 from ensi-platform/v7-pinned
V7 added pinned
2 parents d398e31 + 724e555 commit e9509bc

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/Search/SearchQuery.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class SearchQuery implements SortableQuery, CollapsibleQuery, HighlightingQuery
3939
protected ?int $from = null;
4040
protected array $fields = [];
4141
protected array $include = [];
42+
protected ?array $pinnedIds = null;
4243
protected array $exclude = [];
4344
protected ?string $searchType = null;
4445

@@ -149,12 +150,19 @@ protected function execute(
149150
$dsl = [
150151
'size' => $size,
151152
'from' => $from,
152-
'query' => $this->boolQuery->toDSL(),
153+
'query' => [],
153154
'track_total_hits' => $totals,
154155
'_source' => $this->sourceToDSL($source),
155156
'fields' => $source && $this->fields ? $this->fields : null,
156157
];
157158

159+
if ($this->pinnedIds) {
160+
$dsl['query']['pinned']['ids'] = $this->pinnedIds;
161+
$dsl['query']['pinned']['organic'] = $this->boolQuery->toDSL();
162+
} else {
163+
$dsl['query'] = $this->boolQuery->toDSL();
164+
}
165+
158166
$sorts ??= $this->sorts;
159167
if (!$sorts->isEmpty()) {
160168
$dsl['sort'] = $sorts->toDSL();
@@ -247,6 +255,13 @@ public function setPostFilter(BoolQueryBuilder $boolQueryBuilder): static
247255
return $this;
248256
}
249257

258+
public function pinned(array $ids): static
259+
{
260+
$this->pinnedIds = $ids;
261+
262+
return $this;
263+
}
264+
250265
public function addAggregations(Aggregation $aggregation): static
251266
{
252267
$this->aggregations ??= new AggregationCollection();

0 commit comments

Comments
 (0)