Skip to content

Conversation

@esecules
Copy link
Contributor

@esecules esecules commented Jan 6, 2026

Search results totalCount is set based on the number of items in the results iterator so that it always equals the number of results in the search results set. To make this work, we'll prefetch the entire search if an accurate count is requested along with the search.

If the user requested only a count and nothing else, then we still execute the dedicated COUNT query.

While the total count will always be accurate, Im not sure whether this would be too slow of an approach, particularly if the search would cover a very large number of results.

Fixes #7448

@robogary
Copy link
Contributor

robogary commented Jan 6, 2026

Formatting check succeeded!

@esecules esecules marked this pull request as draft January 6, 2026 20:23
@esecules
Copy link
Contributor Author

esecules commented Jan 6, 2026

Given the test failures, I think there's a gap in my understanding of how the search results table is populated. When I make a search request to my hapi fhir server using _count=X in the initial request, the searchset still gets populated with all the results that matched at the time and when I issue requests for offsets higher than the initial _count, I dont think i see it going back to fetch from HFJ_RESOURCE except for when it's getting the current version for each of the search results.

@esecules esecules changed the title [#7448] Fix _total=accurate #7448 Fix _total=accurate by counting resultIterator iterations and prefetching all if an accurate count is requested Jan 6, 2026
…nt is requested and setting the count based on number of iterations of the result iterator. Still run the dedicated count query if it's just a count of results that was requested, not the results themselves.
@esecules esecules force-pushed the fix-accurate-count branch from 75c5ebd to 602ac81 Compare January 6, 2026 22:34
@esecules esecules marked this pull request as ready for review January 6, 2026 22:44
@esecules
Copy link
Contributor Author

esecules commented Jan 6, 2026

I believe the format check job just need to be restarted. it failed with a timeout trying to add a comment to this PR. I ran mvn spotless:apply on my branch and nothing changed.

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.

_total=accurate is not the same as the total amount of results in the result set

2 participants