Skip to content

refactor: extract SearchParamsBuilder from ElasticSearchIndex - #38

Merged
turegjorup merged 3 commits into
developfrom
refactor/search-params-builder
Jul 8, 2026
Merged

refactor: extract SearchParamsBuilder from ElasticSearchIndex#38
turegjorup merged 3 commits into
developfrom
refactor/search-params-builder

Conversation

@turegjorup

Copy link
Copy Markdown
Contributor

Pull the Elasticsearch search request construction out of ElasticSearchIndex into a small, pure SearchParamsBuilder, so the query-DSL logic can be unit-tested without a live Elasticsearch. Behaviour is unchanged — the full ES-backed suite passes byte-identically.

Changes

  • SearchParamsBuilder (new) — buildParams() composes the match_all default, bool/must combination of filter clauses (with list-flattening so numeric keys don't leak into the JSON), pagination, and the per-index sort. No dependencies → trivially unit-testable.
  • ElasticSearchIndex — injects the builder and delegates in getAll(); the buildParams/buildBody/getSort privates (and their now-unused FilterType/IndexName imports) are removed.
  • Dead code removed — the old buildBody had a non-combined else branch that was unreachable (the loop only runs when filters exist, so $combined was always true).
  • Unit testsSearchParamsBuilderTest (match_all default, bool/must wrapping, list flattening, per-index sort) and a cheap ElasticIndexExceptionTest (400 → "Type: reason", non-400 → "Bad Request").

Verification

  • bin/console lint:container → OK (builder autowired into ElasticSearchIndex).
  • bin/phpunit tests/Unit → 10 tests; full suite 174 tests / 458 assertions green — the refactor is behaviour-preserving.
  • php-cs-fixer clean; PHPStan level 8 + strict clean.

Move the Elasticsearch `search` request construction (query + pagination +
sort) out of ElasticSearchIndex into a pure, dependency-free SearchParamsBuilder
so it can be unit-tested without a live Elasticsearch. Behaviour is unchanged —
the full ES-backed suite passes byte-identically.

- New SearchParamsBuilder with buildParams(); ElasticSearchIndex delegates to it.
- Remove the dead non-combined `else` branch in the old buildBody (the loop only
  runs when filters exist, so the combined path was always taken).
- Unit tests: match_all default, bool/must wrapping, list-clause flattening,
  per-index sort; plus ElasticIndexException::parse400 message parsing.
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

No changes detected in API specification

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@d1e50fc). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop      #38   +/-   ##
==========================================
  Coverage           ?   71.89%           
  Complexity         ?      226           
==========================================
  Files              ?       29           
  Lines              ?      637           
  Branches           ?        0           
==========================================
  Hits               ?      458           
  Misses             ?      179           
  Partials           ?        0           
Flag Coverage Δ
unittests 71.89% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@turegjorup
turegjorup merged commit 8722b8f into develop Jul 8, 2026
12 checks passed
@turegjorup
turegjorup deleted the refactor/search-params-builder branch July 8, 2026 09:25
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