Skip to content

[10.x][Algolia] Support numeric 'whereNotIn' to prevent silent failures#959

Merged
taylorotwell merged 2 commits intolaravel:10.xfrom
sakshamgorey:feature/algolia-where-not-in
Jan 24, 2026
Merged

[10.x][Algolia] Support numeric 'whereNotIn' to prevent silent failures#959
taylorotwell merged 2 commits intolaravel:10.xfrom
sakshamgorey:feature/algolia-where-not-in

Conversation

@sakshamgorey
Copy link
Contributor

@sakshamgorey sakshamgorey commented Jan 24, 2026

[Algolia] Support numeric whereNotIn to prevent silent failures

Description

Currently, the Algolia engine silently fails when whereNotIn is used. The Builder accepts the method call, but AlgoliaEngine completely ignores the exclusion list, returning records that the developer explicitly intended to hide.

This PR implements whereNotIn support using Algolia's numericFilters, bringing parity with where and whereIn.

Before

// Returns invoices with status_code 7 (Cancelled) and 0 (Draft) (Silent Failure)
Invoice::search('ACME Corp')->whereNotIn('status_code', [0, 7])->get();

After

// Correctly excludes Cancelled and Draft invoices
Invoice::search('ACME Corp')->whereNotIn('status_code', [0, 7])->get();

Technical Implementation

Since Algolia's numericFilters lacks a native "NOT IN" operator, we simulate it using AND logic:

  • whereIn (Existing): Maps to a nested array [['id=1', 'id=2']] (interpreted as OR).
  • whereNotIn (New): Uses flatMap to generate a top-level list ['id!=1', 'id!=2'] (interpreted as AND).

Note: Consistent with the existing engine implementation, this supports numeric values only.

Tests

Comprehensive tests were added to Algolia3EngineTest and Algolia4EngineTest to verify:

  • Correct Logic: whereNotIn('foo', [1, 2]) generates ['foo!=1', 'foo!=2'].
  • Empty Arrays: Passing an empty array is safely ignored.
  • Mixed Queries: Validated that where, whereIn, and whereNotIn work correctly when combined in a single query.

Benefit to end users

Developers can now reliably use whereNotIn to exclude specific numeric records (e.g., status codes, IDs) from their search results without needing manual post-processing. It eliminates a dangerous silent failure where sensitive or unwanted data could be exposed.

Reasons it does not break any existing features

This change is purely additive. It processes whereNotIn constraints which were previously ignored. Existing where and whereIn functionality remains untouched, and applications not using whereNotIn will experience no change in behavior.

@taylorotwell taylorotwell merged commit 08de9bf into laravel:10.x Jan 24, 2026
23 checks passed
@sakshamgorey sakshamgorey deleted the feature/algolia-where-not-in branch January 29, 2026 17:18
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.

2 participants