Skip to content

Commit

Permalink
Merge pull request #551 from ministryofjustice/bugfix/DST-9372-score-…
Browse files Browse the repository at this point in the history
…reduction

DST-9372 Fix search ordering following case-sensitivity changes
  • Loading branch information
jamesmacbeth-unilink authored Jul 28, 2021
2 parents 28e3acf + 20a60b6 commit 43c17a2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.time.LocalDate;
import java.util.List;

@With
@Getter
@ToString
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package uk.co.bconline.ndelius.model.entity;

import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Type;

import javax.persistence.Column;
Expand All @@ -11,7 +14,6 @@
import java.util.HashSet;
import java.util.Set;

@With
@Getter
@Entity
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public List<SearchResult> search(String query, boolean includeInactiveUsers, Set
val results = SearchUtils.streamTokens(query).parallel()
.flatMap(token -> searchForToken(token, includeInactiveUsers, datasets))
.map(searchResultTransformer::map)
.collect(groupingByConcurrent(SearchResult::getUsername, reducing(searchResultTransformer::reduce)))
.collect(groupingByConcurrent(SearchResult::getUsername, reducing((a, b) -> a.withScore(a.getScore() + b.getScore()))))
.values().stream().flatMap(Optional::stream)
.collect(toList());
log.debug("Found {} DB results in {}ms", results.size(), MILLIS.between(t, LocalDateTime.now()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public SearchResult reduce(SearchResult a, SearchResult b) {
.teams(ofNullable(a.getTeams()).orElseGet(b::getTeams))
.endDate(ofNullable(a.getEndDate()).orElseGet(b::getEndDate))
.email(ofNullable(a.getEmail()).orElseGet(b::getEmail))
.score(a.getScore() > 0.0 ? a.getScore() : b.getScore())
.sources(Stream.concat(a.getSources().stream(), b.getSources().stream()).distinct().collect(toList()))
.build();
}
Expand All @@ -105,8 +104,4 @@ public SearchResultEntity reduceTeams(SearchResultEntity a, SearchResultEntity b
reduced.getTeams().addAll(b.getTeams());
return reduced;
}

public SearchResultEntity reduce(SearchResultEntity a, SearchResultEntity b) {
return a.withScore(a.getScore() + b.getScore());
}
}

0 comments on commit 43c17a2

Please sign in to comment.