Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lrosenstrom committed Jan 28, 2025
1 parent 5718480 commit e350949
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions whelk-core/src/main/groovy/whelk/search2/FacetTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,24 @@ public List<Map<String, Object>> sortObservationsAsTree(List<Map<String, Object>
.map(o -> jsonLd.toTermKey(get(o, List.of("object", "@id"), "")))
.collect(Collectors.toList());

List<String> roots = observationsAsTypeKeys.stream().filter(this::isRootNode).toList();

List<String> rootCandidates = observationsAsTypeKeys.stream().filter(this::isRootNode).toList();
String rootKey;
Map<String, Object> root;

if (roots.size() == 1) {
Map<String, Object> root = observations.stream()
.filter(o -> jsonLd.toTermKey(get(o, List.of("object", "@id"), "")).equals(roots.getFirst()))
if (rootCandidates.size() == 1) {
root = observations.stream()
.filter(o -> jsonLd.toTermKey(get(o, List.of("object", "@id"), "")).equals(rootCandidates.getFirst()))
.findFirst()
.orElse(null);
tree.add(root);
queue.add(root);
rootKey = jsonLd.toTermKey(get(root, List.of("object", "@id"), ""));
} else {
rootKey = getAbsentRoot(observationsAsTypeKeys.getFirst());
observationsAsTypeKeys.add(rootKey);
Map<String, Object> root = createFakeObservation(rootKey);
root = createFakeObservation(rootKey);
observations.add(root);
tree.add(root);
queue.add(root);

}
tree.add(root);
queue.add(root);

observationsAsTypeKeys.forEach(typeKey -> {
if (!typeKey.equals(rootKey)) {
Expand Down

0 comments on commit e350949

Please sign in to comment.