Skip to content

Commit

Permalink
CSW server / Use portal filter in GetRecordById requests / Only check…
Browse files Browse the repository at this point in the history
… total.
  • Loading branch information
fxprunayre committed Apr 10, 2024
1 parent 83be152 commit f6670e9
Showing 1 changed file with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import co.elastic.clients.elasticsearch._types.SortOptions;
import co.elastic.clients.elasticsearch.core.SearchResponse;
import co.elastic.clients.elasticsearch.core.search.Hit;
import co.elastic.clients.elasticsearch.core.search.TotalHits;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import jeeves.server.context.ServiceContext;
Expand Down Expand Up @@ -60,12 +61,7 @@

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;


public class SearchController {
Expand Down Expand Up @@ -137,12 +133,9 @@ public Element retrieveMetadata(ServiceContext context, String id, ElementSetNam
ObjectMapper objectMapper = new ObjectMapper();
esJsonQuery = objectMapper.readTree(jsonQuery);

Set<String> fieldsToRetrieve = new HashSet<>();
fieldsToRetrieve.add("uuid");
SearchResponse result = searchManager.query(esJsonQuery, fieldsToRetrieve, 0, 1);
TotalHits total = searchManager.query(esJsonQuery, new HashSet<>(), 0, 0).hits().total();

long numMatches = result.hits().hits().size();
if (numMatches == 0) {
if (Optional.ofNullable(total).map(TotalHits::value).orElse(0L) == 0) {
return null;
}
} catch (Exception e) {
Expand Down

0 comments on commit f6670e9

Please sign in to comment.