Skip to content

Commit

Permalink
CSW / GetRecords / Number of matches is not total match
Browse files Browse the repository at this point in the history
Follow up of #7599

`result.hits().hits().size()` returns number of records in response, not total hits matching search. `numberOfRecordsMatched` is wrong.

```
  <csw:SearchResults numberOfRecordsMatched="10" numbe
```
  • Loading branch information
fxprunayre committed Apr 10, 2024
1 parent c67fea3 commit e63f0b3
Showing 1 changed file with 4 additions and 2 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 @@ -458,8 +459,9 @@ public Element search(ServiceContext context, int startPos, int maxRecords,
SearchResponse result = searchManager.query(esJsonQuery, new HashSet<>(), startPos-1, maxRecords, sort);

List<Hit> hits = result.hits().hits();

long numMatches = result.hits().hits().size();

TotalHits total = result.hits().total();
long numMatches = total != null ? total.value() : 0;

if (numMatches != 0 && startPos > numMatches) {
throw new InvalidParameterValueEx("startPosition", String.format(
Expand Down

0 comments on commit e63f0b3

Please sign in to comment.