Skip to content

Populate hit counts in JSON results format across load-more feature settings - #457

Open
matt-bernhardt wants to merge 5 commits into
mainfrom
quepid-hits
Open

Populate hit counts in JSON results format across load-more feature settings#457
matt-bernhardt wants to merge 5 commits into
mainfrom
quepid-hits

Conversation

@matt-bernhardt

@matt-bernhardt matt-bernhardt commented Aug 27, 2026

Copy link
Copy Markdown
Member

This restores an attribute in our search results - specific to the JSON format response - upon which our relevance platform depends, but which is going to go away with the next release of the application.

The change follows a TDD pattern of development: the first commit expands our test suite to reveal the problem (the loss of "hit counts" in the response, which will cause a problem with our Quepid platform). The second commit resolves the problem by restoring the value in the two conditions across which the application will likely operate.

Developer

Accessibility
  • ANDI or WAVE has been run in accordance to our guide.
  • This PR contains no changes to the view layer.
  • New issues flagged by ANDI or WAVE have been resolved.
  • New issues flagged by ANDI or WAVE have been ticketed (link in the Pull Request details above).
  • No new accessibility issues have been flagged.
New ENV
  • All new ENV is documented in README.
  • All new ENV has been added to Heroku Pipeline, Staging and Prod.
  • ENV has not changed.
Approval beyond code review
  • UXWS/stakeholder approval has been confirmed.
  • UXWS/stakeholder review will be completed retroactively.
  • UXWS/stakeholder review is not needed.
Additional context needed to review

E.g., if the PR includes updated dependencies and/or data
migration, or how to confirm the feature is working.

Code Reviewer

Code
  • I have confirmed that the code works as intended.
  • Any CodeClimate issues have been fixed or confirmed as
    added technical debt.
Documentation
  • The commit message is clear and follows our guidelines
    (not just this pull request message).
  • The documentation has been updated or is unnecessary.
  • New dependencies are appropriate or there were no changes.
Testing
  • There are appropriate tests covering any new functionality.
  • No additional test coverage is required.

@qltysh

qltysh Bot commented Aug 27, 2026

Copy link
Copy Markdown

❌ 4 blocking issues (4 total)

Tool Category Rule Count
rubocop Lint Class has too many lines. [364/100] 1
rubocop Lint Assignment Branch Condition size for results is too high. [<7, 35, 8> 36.58/17] 1
rubocop Lint Cyclomatic complexity for results is too high. [8/7] 1
rubocop Lint Method has too many lines. [26/10] 1

Comment thread app/controllers/search_controller.rb
Comment thread test/controllers/search_controller_test.rb Outdated
Comment thread test/controllers/search_controller_test.rb Outdated
Comment thread test/controllers/search_controller_test.rb Outdated
Comment thread test/controllers/search_controller_test.rb Outdated
Comment thread test/controllers/search_controller_test.rb Outdated
Comment thread test/controllers/search_controller_test.rb Outdated
Comment thread test/controllers/search_controller_test.rb Outdated
Comment thread test/controllers/search_controller_test.rb Outdated
Comment thread test/controllers/search_controller_test.rb Outdated
@coveralls

coveralls commented Aug 27, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 33206635348

Coverage increased (+0.004%) to 98.304%

Details

  • Coverage increased (+0.004%) from the base build.
  • Patch coverage: 5 of 5 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 1710
Covered Lines: 1681
Line Coverage: 98.3%
Coverage Strength: 82.21 hits per line

💛 - Coveralls

@mitlib
mitlib temporarily deployed to timdex-ui-pi-quepid-hit-kxh4s2 August 27, 2026 20:30 Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Restores the pagination.hits attribute in the JSON /results response so external relevance tooling (Quepid) can continue to read total hit counts regardless of whether the load-more pagination feature flag is enabled.

Changes:

  • Adds controller tests asserting that JSON responses include pagination.hits.
  • Updates SearchController JSON rendering to populate pagination based on the active pagination mode (legacy vs. load-more).

Reviewed changes

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

File Description
test/controllers/search_controller_test.rb Adds assertions (and a new case) to ensure JSON responses include pagination.hits, including when load-more is enabled.
app/controllers/search_controller.rb Switches JSON pagination payload to be derived from either @pagination or @load_more[:total_hits] via a helper method.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +56 to +61
# This returns the total result count from whichever instance variable is present
def hit_count
return @pagination unless pagination_load_more_enabled?

{ hits: @load_more[:total_hits] }
end

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I see this suggestion, and am rejecting the specific change while trying to respond to the observation underlying it. I've refactored the hit_count method to explicitly only return the value we care about, in a way that is more robust to the conditions the data might take running through the method.

This is not the agent's suggested change, but it does respond to what I
think the agent's criticism was - inconsistent shape in the response,
and a lack of robustness to different data conditions.

My response is to focus on the one value that Quepid needs - the number
of hits - and strip out all the other parameters that could be found
between the @Pagination and @load_more instance variables.

The new hit_count method is also more robust to nulls by using the
&.[]() syntax, and falls back to 0 if a value cannot be extracted.
@mitlib
mitlib temporarily deployed to timdex-ui-pi-quepid-hit-kxh4s2 August 28, 2026 15:32 Inactive
format.json { render json: { results: @results, hits: hit_count, errors: @errors } }
format.turbo_stream { render :results }
format.html { render :results }
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Found 3 issues:

1. Assignment Branch Condition size for results is too high. [<7, 35, 8> 36.58/17] [rubocop:Metrics/AbcSize]


2. Cyclomatic complexity for results is too high. [8/7] [rubocop:Metrics/CyclomaticComplexity]


3. Method has too many lines. [26/10] [rubocop:Metrics/MethodLength]

@jazairi jazairi self-assigned this Aug 28, 2026

@jazairi jazairi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good! Could we add a test catching the fallback to 0 you added in response to Copilot's review?

@mitlib
mitlib temporarily deployed to timdex-ui-pi-quepid-hit-kxh4s2 August 28, 2026 20:00 Inactive
Comment thread test/controllers/search_controller_test.rb Outdated
Comment thread test/controllers/search_controller_test.rb Outdated
@mitlib
mitlib temporarily deployed to timdex-ui-pi-quepid-hit-kxh4s2 August 28, 2026 20:04 Inactive
@matt-bernhardt

Copy link
Copy Markdown
Member Author

Okay @jazairi - I've added a test to exercise the || 0 pathway that this utilizes. You're more familiar with mocking logic than I am, so I'm hoping that this approach is sufficient. It is a pretty bare-bones way of setting up the data to exercise those pathways. Let me know what you think?

@matt-bernhardt
matt-bernhardt requested a review from jazairi August 28, 2026 20:45

@jazairi jazairi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this confirms the fallback behavior well. Thanks!

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.

5 participants