Skip to content

fix: do not silently drop non-numeric Algolia hit ids / 非数値IDのサイレントドロップを防ぐ - #604

Merged
zigzagdev merged 2 commits into
fix/algolia-search-adapter-design-gapsfrom
fix/algolia-non-numeric-id-handling
Oct 26, 2026
Merged

zigzagdev merged 2 commits into
fix/algolia-search-adapter-design-gapsfrom
fix/algolia-non-numeric-id-handling

Conversation

@zigzagdev

Copy link
Copy Markdown
Owner

Motivation / 目的

AlgoliaWorldHeritageSearchAdapter::search() extracted ids with (int) $h['id']
inside array_map, then ran the result through array_filter. A non-numeric
id/objectID casts to 0, which array_filter's default truthy check then
silently removes. A data inconsistency on the Algolia side (e.g. a corrupted or
non-numeric id) would disappear from search results with no error or log trace.

AlgoliaWorldHeritageSearchAdapter::search()はarray_map内で(int) $h['id']を使ってID
を抽出し、その結果をarray_filterに通していました。非数値のid/objectIDは0にキャスト
され、array_filterのデフォルトのtruthy判定によって黙って除外されます。Algolia側のデータ
不整合(壊れた、または非数値のid)があった場合、エラーもログも出さずに検索結果から消えて
いました。

What I have done / 実施内容

  • Replaced the array_map/array_filter chain with an explicit loop that
    checks is_numeric() before casting
  • On a non-numeric id, logs Log::warning() with both the raw id and
    objectID, then skips just that hit (the rest of the results still return)
  • Added a test covering a response with a mixed valid/non-numeric hit
  • Changed AlgoliaWorldHeritageSearchAdapterTest's base class from plain
    PHPUnit TestCase to Laravel's Tests\TestCase so the Log facade can be
    asserted on; existing tests are unaffected by this

Test Results / テスト結果

  • AlgoliaWorldHeritageSearchAdapterTest: 6 passed
  • php artisan test (full suite): 227 passed, no regressions

Closes #600
Part of #592

@github-actions github-actions Bot added bug Something isn't working backend labels Oct 25, 2026
@zigzagdev zigzagdev linked an issue Oct 25, 2026 that may be closed by this pull request
2 tasks
@codecov

codecov Bot commented Oct 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.91667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 68.19%. Comparing base (84b835d) to head (132befc).

Files with missing lines Patch % Lines
...tage/Adapter/AlgoliaWorldHeritageSearchAdapter.php 91.66% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                             Coverage Diff                              @@
##             fix/algolia-search-adapter-design-gaps     #604      +/-   ##
============================================================================
+ Coverage                                     68.05%   68.19%   +0.13%     
- Complexity                                     1731     1733       +2     
============================================================================
  Files                                           153      153              
  Lines                                          9159     9202      +43     
============================================================================
+ Hits                                           6233     6275      +42     
- Misses                                         2926     2927       +1     
Files with missing lines Coverage Δ
...ge/Tests/AlgoliaWorldHeritageSearchAdapterTest.php 100.00% <100.00%> (ø)
...tage/Adapter/AlgoliaWorldHeritageSearchAdapter.php 87.23% <91.66%> (-0.13%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zigzagdev zigzagdev self-assigned this Oct 26, 2026

@zigzagdev zigzagdev left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

LGTM

@zigzagdev
zigzagdev merged commit 287b1ec into fix/algolia-search-adapter-design-gaps Oct 26, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Do not silently drop non-numeric IDs during ID extraction

1 participant