fix(search): use in-memory sort for SENDER to include documents with null sender
Some checks failed
CI / Unit & Component Tests (push) Has been cancelled
CI / Backend Unit Tests (push) Has been cancelled
CI / Unit & Component Tests (pull_request) Has been cancelled
CI / Backend Unit Tests (pull_request) Has been cancelled

INNER JOIN from Sort.by("sender.lastName") was excluding docs without a sender.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-06 14:15:03 +02:00
parent 07dbe152e2
commit bc397048b7
2 changed files with 41 additions and 1 deletions

View File

@@ -291,11 +291,15 @@ public class DocumentService {
.and(hasTagPartial(tagQ))
.and(hasStatus(status));
Sort springSort = resolveSort(sort, dir);
if (sort == DocumentSort.RECEIVER) {
List<Document> results = documentRepository.findAll(spec);
return sortByFirstReceiver(results, dir);
}
if (sort == DocumentSort.SENDER) {
List<Document> results = documentRepository.findAll(spec);
return sortBySender(results, dir);
}
Sort springSort = resolveSort(sort, dir);
return documentRepository.findAll(spec, springSort);
}
@@ -312,6 +316,22 @@ public class DocumentService {
};
}
private List<Document> sortBySender(List<Document> documents, String dir) {
boolean ascending = "ASC".equalsIgnoreCase(dir);
Comparator<String> nullSafeComparator = (a, b) -> {
if (a.isEmpty() && b.isEmpty()) return 0;
if (a.isEmpty()) return ascending ? 1 : -1;
if (b.isEmpty()) return ascending ? -1 : 1;
return ascending ? a.compareTo(b) : b.compareTo(a);
};
return documents.stream()
.sorted(Comparator.comparing(doc -> {
Person s = doc.getSender();
return s != null ? s.getLastName() + " " + s.getFirstName() : "";
}, nullSafeComparator))
.toList();
}
private List<Document> sortByFirstReceiver(List<Document> documents, String dir) {
boolean ascending = "ASC".equalsIgnoreCase(dir);
Comparator<String> nullSafeComparator = (a, b) -> {