Skip to content

Commit ca330c4

Browse files
committed
change inconsistant null check in peelback search requests method
1 parent cb30c27 commit ca330c4

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

src/main/java/uk/gov/companieshouse/search/api/service/search/impl/alphabetical/AlphabeticalSearchRequestService.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.util.Collections;
1111
import java.util.List;
1212
import java.util.Map;
13-
import java.util.Optional;
1413
import org.elasticsearch.search.SearchHit;
1514
import org.elasticsearch.search.SearchHits;
1615
import org.springframework.stereotype.Service;
@@ -141,17 +140,12 @@ private List<Company> prepareSearchResultsWithTopHit(Integer size, String reques
141140
}
142141

143142
public SearchHits peelbackSearchRequest(SearchHits hits, String orderedAlphakey, String requestId)
144-
throws IOException {
143+
throws IOException {
145144

146145
Integer fallbackQueryLimit = environmentReader.getMandatoryInteger(ALPHABETICAL_FALLBACK_QUERY_LIMIT);
147146

148147
for (int i = 0; i < orderedAlphakey.length(); i++) {
149-
150-
long totalHits = Optional.ofNullable(hits.getTotalHits())
151-
.map(th -> th.value)
152-
.orElse(0L);
153-
154-
if (totalHits > 0 || i == fallbackQueryLimit) {
148+
if (hits.getTotalHits() != null && hits.getTotalHits().value > 0 || i == fallbackQueryLimit) {
155149
return hits;
156150
}
157151

src/main/java/uk/gov/companieshouse/search/api/service/search/impl/dissolved/DissolvedSearchRequestService.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,13 @@ private SearchHits getSearchHits(String orderedAlphakey, String requestId) throw
244244
}
245245

246246
public SearchHits peelbackSearchRequest(SearchHits hits, String orderedAlphaKey, String requestId)
247-
throws IOException {
247+
throws IOException {
248248

249249
Integer fallbackQueryLimit = environmentReader.getMandatoryInteger(DISSOLVED_ALPHABETICAL_FALLBACK_QUERY_LIMIT);
250250

251251
for (int i = 0; i < orderedAlphaKey.length(); i++) {
252252

253-
long totalHits = Optional.ofNullable(hits.getTotalHits())
254-
.map(th -> th.value)
255-
.orElse(0L);
256-
257-
if (totalHits > 0 || i == fallbackQueryLimit) {
253+
if (hits.getTotalHits() != null && hits.getTotalHits().value > 0 || i == fallbackQueryLimit) {
258254
return hits;
259255
}
260256

0 commit comments

Comments
 (0)