Skip to content

fix: send search_type=query_then_fetch as a top-level param in Search::count()#2302

Open
ruflin wants to merge 1 commit into
9.xfrom
fix/search-count-search-type
Open

fix: send search_type=query_then_fetch as a top-level param in Search::count()#2302
ruflin wants to merge 1 commit into
9.xfrom
fix/search-count-search-type

Conversation

@ruflin

@ruflin ruflin commented Apr 30, 2026

Copy link
Copy Markdown
Owner

Summary

Elastica\Search::count() built its parameter array like this:

$params = [
    'body' => $query->toArray(),
    [self::OPTION_SEARCH_TYPE => self::OPTION_SEARCH_TYPE_QUERY_THEN_FETCH],
];

That second entry is a numeric-keyed sub-array, which the upstream
elasticsearch-php Client::search() ignores. The intended
search_type=query_then_fetch query parameter never made it to
Elasticsearch.

The fix flattens it back to a string-keyed entry. A new functional test
asserts that the option arrives in the HTTP request's query string.

Identified during a P0/P1 code-review pass.

Test plan

  • `make docker-run-phpunit PHPUNIT_OPTIONS="--filter=testCountSendsSearchTypeQueryThenFetch"`
  • CI matrix (PHP 8.1–8.5)
  • PHPStan + php-cs-fixer

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an issue in the count method where the search_type=query_then_fetch option was not being properly preserved due to incorrect parameter structure.
  • Tests

    • Added test coverage to verify that the search_type parameter is correctly set and included in search requests.

…::count()

The `$params` literal in `Search::count()` wrapped the search-type option
in a numeric-keyed sub-array:

    $params = [
        'body' => $query->toArray(),
        [self::OPTION_SEARCH_TYPE => self::OPTION_SEARCH_TYPE_QUERY_THEN_FETCH],
    ];

The upstream `Client::search()` ignores numeric-keyed sub-arrays, so the
option never reached Elasticsearch. Hoist the entry to a string-keyed
member of `$params` and add a functional test asserting it lands in the
HTTP request's query string.
Copilot AI review requested due to automatic review settings April 30, 2026 20:25
@coderabbitai

coderabbitai Bot commented Apr 30, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 66ef8d8d-d5d4-463f-bd68-bf714da23f6a

📥 Commits

Reviewing files that changed from the base of the PR and between d0c0d60 and 0bd5b5b.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • src/Search.php
  • tests/SearchTest.php

📝 Walkthrough

Walkthrough

This change fixes a bug in Elastica\Search::count() where the search_type=query_then_fetch option was incorrectly wrapped in a numeric-keyed sub-array, preventing proper parameter handling. The fix restructures the parameter directly as an associative key, adds verification test coverage, and documents the resolution.

Changes

Cohort / File(s) Summary
Bugfix Implementation
src/Search.php
Modified count() method to set search_type as a direct associative array entry instead of nesting it within a numeric-keyed sub-array structure.
Testing & Documentation
tests/SearchTest.php, CHANGELOG.md
Added functional test to verify search_type parameter preservation in HTTP query; documented bugfix in changelog under Fixed section.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A search parameter, once wrapped with care,
Now spreads its wings in associative air,
No numeric keys to hide it away,
The test keeps it true, come what may! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the primary change: fixing the search_type parameter placement in Search::count() from a nested array to a top-level parameter.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/search-count-search-type

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 4/8 reviews remaining, refill in 23 minutes and 6 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes Elastica\Search::count() so the search_type=query_then_fetch option is sent as a proper top-level request parameter (instead of being wrapped in a numeric-keyed sub-array that gets ignored by the upstream client), and adds a functional test to assert the query parameter is present on the outgoing HTTP request.

Changes:

  • Flattened the Search::count() $params array so search_type is a top-level key.
  • Added a functional test verifying search_type=query_then_fetch is present in the last request’s query string.
  • Documented the fix in the Unreleased changelog.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Search.php Fixes request parameter construction in Search::count() so search_type is actually transmitted.
tests/SearchTest.php Adds a functional regression test asserting search_type is present in the outgoing request.
CHANGELOG.md Records the bugfix in the Unreleased “Fixed” section.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread CHANGELOG.md
### Deprecated
### Removed
### Fixed
* Fixed `Elastica\Search::count()` silently dropping the `search_type=query_then_fetch` option due to a malformed array literal that wrapped it in a numeric-keyed sub-array.

Copilot AI Apr 30, 2026

Copy link

Choose a reason for hiding this comment

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

In the Unreleased section, other changelog bullets include a PR/issue reference link; this entry currently has none. Consider appending the PR number link for consistency and easier traceability.

Copilot uses AI. Check for mistakes.
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