Skip to content

feat: Update to scout v11#365

Open
MarioAlexandruDan wants to merge 4 commits intomasterfrom
feat/scout-v11
Open

feat: Update to scout v11#365
MarioAlexandruDan wants to merge 4 commits intomasterfrom
feat/scout-v11

Conversation

@MarioAlexandruDan
Copy link
Copy Markdown
Contributor

@MarioAlexandruDan MarioAlexandruDan commented Mar 31, 2026

Q A
Bug fix? no
New feature? yes
BC breaks? yes
Related Issue Fix #364
Need Doc update yes

Describe your change

Upgrade Laravel Scout from v10 to v11 [API-364](https://algolia.atlassian.net/browse/API-364)

This PR upgrades laravel/scout from ^10.11.6 to ^11.0.0, removing the legacy numericFilters array-based filtering and replacing it with Scout v11's native filters string syntax. Where conditions are now stored using Scout v11's structured ['field', 'operator', 'value'] format and $whereIns property, removing all manual $wheres manipulation.

Breaking Changes

  • Laravel Scout minimum version raised to ^11.0.0. Scout 10.x is no longer supported. Scout v11 removed numericFilters ([11.x] Removed numeric filters laravel/scout#839) in favour of the filters string parameter.
  • filters() return type changed from array to string. Any subclass overriding filters() must be updated to return a boolean expression string (e.g. field > 100 AND (id=1 OR id=2)) instead of an array.

@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Mar 31, 2026

Not up to standards ⛔

🔴 Issues 4 high

Alerts:

⚠ 4 issues (≤ 0 issues of at least high severity)

Results:
4 new issues

Category Results
Security 4 high

View in Codacy

🟢 Metrics 0 duplication

Metric Results
Duplication 0

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

@MarioAlexandruDan MarioAlexandruDan self-assigned this Mar 31, 2026
@MarioAlexandruDan MarioAlexandruDan marked this pull request as ready for review April 1, 2026 07:19
@MarioAlexandruDan MarioAlexandruDan requested a review from Fluf22 April 2, 2026 12:54
Copy link
Copy Markdown
Contributor

@Fluf22 Fluf22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth noting in the upgrade guide: since the engine now uses the filters key instead of numericFilters, any manual ->with(['filters' => '...']) will be overwritten by the engine's computed filters. Users who were combining with(['filters' => ...]) alongside where() clauses need to move everything into where() calls instead.

Comment on lines 64 to 105
/**
* {@inheritdoc}
*/
public function search(Builder $builder)
{
return $this->performSearch($builder, array_filter([
'numericFilters' => $this->filters($builder),
'filters' => $this->filters($builder),
'hitsPerPage' => $builder->limit,
]));
}

/**
* {@inheritdoc}
*/
public function paginate(Builder $builder, $perPage, $page)
{
return $this->performSearch($builder, [
'numericFilters' => $this->filters($builder),
'filters' => $this->filters($builder),
'hitsPerPage' => $perPage,
'page' => $page - 1,
]);
}

/**
* {@inheritdoc}
*/
public function map(Builder $builder, $results, $searchable)
{
if (count($results['hits']) === 0) {
return $searchable->newCollection();
}

return app(ModelsResolver::class)->from($builder, $searchable, $results);
}

/**
* {@inheritdoc}
*/
public function lazyMap(Builder $builder, $results, $searchable)
{
return LazyCollection::make($this->map($builder, $results, $searchable));
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are not needed anymore since they are exactly the same than the grand-parent class: https://github.com/laravel/scout/blob/11.x/src/Engines/AlgoliaEngine.php#L99-L122

Comment thread src/Builder.php
public function whereBetween($field, array $values): self
{
return $this->where("$field:", "{$this->transform($values[0])} TO {$this->transform($values[1])}");
return parent::where($field, ':', [$this->transform($values[0]), $this->transform($values[1])]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is worth documenting, I believe, since it's a non-standard entry in $wheres: for operator ':', the value is an array instead of scalar.
It works because filters() has the matching match arm, but anyone iterating $builder->wheres expecting the standard Scout v11 format will have a surprise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Laravel Scout v11 support

2 participants