Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix descending sort #4661

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,8 @@ public override async Task<SearchResult> SearchAsync(SearchOptions searchOptions
{
// We seem to have run a sort which has returned less results than what max we can return.
// Let's determine whether we need to execute another query or not.
//
// When order is descending, what would make DidWeSearchForSortValue false?
// Right now if no results are found that have the sort value and the order is descending this won't run.
// What is the point of DidweSearchForSortValue at all???
if ((sqlSearchOptions.Sort[0].sortOrder == SortOrder.Ascending && sqlSearchOptions.DidWeSearchForSortValue.HasValue && !sqlSearchOptions.DidWeSearchForSortValue.Value) ||
(sqlSearchOptions.Sort[0].sortOrder == SortOrder.Descending && sqlSearchOptions.DidWeSearchForSortValue.HasValue && sqlSearchOptions.DidWeSearchForSortValue.Value && !sqlSearchOptions.SortHasMissingModifier))
(sqlSearchOptions.Sort[0].sortOrder == SortOrder.Descending && sqlSearchOptions.DidWeSearchForSortValue.HasValue && sqlSearchOptions.DidWeSearchForSortValue.Value && !sqlSearchOptions.SortHasMissingModifier) || (sqlSearchOptions.Sort[0].sortOrder == SortOrder.Descending && resultCount == 0))
{
if (sqlSearchOptions.MaxItemCount - resultCount == 0)
{
Expand Down Expand Up @@ -552,6 +548,7 @@ await _sqlRetryService.ExecuteSql(
clonedSearchOptions.Sort.Count > 0 &&
clonedSearchOptions.Sort[0].searchParameterInfo.Code != KnownQueryParameterNames.LastUpdated)
{
// If there is an extra column for sort value, we know we have searched for sort values. If no results were returned, we don't know if we have searched for sort values so we need to assume we did so we run the second phase.
sqlSearchOptions.DidWeSearchForSortValue = numberOfColumnsRead > _defaultNumberOfColumnsReadFromResult;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,7 @@ public async Task GivenOrg_WhenSearchedWithPartOfAndSortedByName_ThenOrgsAreRetu

/*
* Needs investigation, this breaks GivenPatients_WhenSearchedWithSortParamAndMissingIdentifier_SearchResultsReturnedShouldHonorMissingIdentifier
*/
[Theory]
[InlineData("address-postalcode")]
[InlineData("-address-postalcode")]
Expand All @@ -1132,7 +1133,6 @@ public async Task GivenNoResourcesWithSortValue_WhenSearchedWithSortParameter_Th

SortTestsAssert.AssertNumberOfResources(patients, returnedResults);
}
*/

private async Task<Patient[]> CreatePatients(string tag)
{
Expand Down
Loading