refactor: extract SearchParamsBuilder from ElasticSearchIndex - #38
Merged
Conversation
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.
…rams-builder # Conflicts: # CHANGELOG.md
…rams-builder # Conflicts: # CHANGELOG.md
|
✅ No changes detected in API specification |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull the Elasticsearch
searchrequest construction out ofElasticSearchIndexinto a small, pureSearchParamsBuilder, 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 thematch_alldefault,bool/mustcombination 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 ingetAll(); thebuildParams/buildBody/getSortprivates (and their now-unusedFilterType/IndexNameimports) are removed.buildBodyhad a non-combinedelsebranch that was unreachable (the loop only runs when filters exist, so$combinedwas always true).SearchParamsBuilderTest(match_all default, bool/must wrapping, list flattening, per-index sort) and a cheapElasticIndexExceptionTest(400 → "Type: reason", non-400 → "Bad Request").Verification
bin/console lint:container→ OK (builder autowired intoElasticSearchIndex).bin/phpunit tests/Unit→ 10 tests; full suite 174 tests / 458 assertions green — the refactor is behaviour-preserving.