diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SynchronousSearchSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SynchronousSearchSvcImpl.java index 317b8fa2105..6b947683e9a 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SynchronousSearchSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SynchronousSearchSvcImpl.java @@ -130,6 +130,7 @@ public class SynchronousSearchSvcImpl implements ISynchronousSearchSvc { List> contentAndTerms = theParams.get(Constants.PARAM_CONTENT); List> textAndTerms = theParams.get(Constants.PARAM_TEXT); + // TODO - this count query should not be grouped count = theSb.createCountQuery( theParams, theSearchUuid, theRequestDetails, theRequestPartitionId); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java index e457349252b..3103b0452eb 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java @@ -762,7 +762,7 @@ public class SearchBuilder implements ISearchBuilder { * if the MaxResultsToFetch is null, we are requesting "everything", * so we'll let the db do the deduplication (instead of in-memory) */ - if (theOffset != null || myMaxResultsToFetch == null) { + if (theOffset != null || (myMaxResultsToFetch == null && !theCountOnlyFlag)) { queryStack3.addGrouping(); queryStack3.setUseAggregate(true); } @@ -2507,7 +2507,11 @@ public class SearchBuilder implements ISearchBuilder { } } - mySearchRuntimeDetails.setFoundMatchesCount(myPidSet.size()); + if (myMaxResultsToFetch == null) { + mySearchRuntimeDetails.setFoundIndexMatchesCount(myNonSkipCount); + } else { + mySearchRuntimeDetails.setFoundMatchesCount(myPidSet.size()); + } } finally { // search finished - fire hooks