From 3488d1b86b59c12767a8aae7ff4976cea3aa53fb Mon Sep 17 00:00:00 2001 From: MatthieuBarbet Date: Fri, 23 Feb 2024 17:52:07 +0100 Subject: [PATCH] Feat: use source to get search after values --- .../services/ElasticExploreService.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/arlas-core/src/main/java/io/arlas/server/core/impl/elastic/services/ElasticExploreService.java b/arlas-core/src/main/java/io/arlas/server/core/impl/elastic/services/ElasticExploreService.java index f8aa28aa8..79c715604 100644 --- a/arlas-core/src/main/java/io/arlas/server/core/impl/elastic/services/ElasticExploreService.java +++ b/arlas-core/src/main/java/io/arlas/server/core/impl/elastic/services/ElasticExploreService.java @@ -173,15 +173,35 @@ private HashMap getLinks(Search searchRequest, CollectionReference if (lastIndex >= 0 && sizeParam == nbhits && sortParam != null && (afterParam != null || sortParam.contains(collectionReference.params.idPath))) { next = new Link(); next.method = method; - // Use sorted value of last element return by ES to build after param of next & previous link - lastHitAfter = searchHitList.get(lastIndex).sort().stream().map(FieldValue::_toJsonString).collect(Collectors.joining(",")); + //Warning the case where the sort contains geodistance and a no timestamp date is not covered + if(!sortParam.contains("geodistance")){ + // We can't use the sort() method because it transforms all the date in timestamp and dont keep the original format + // Use sorted value of last element return by ES to build after param of next & previous link + lastHitAfter = Arrays.asList(sortParam.split(",")).stream() + .map(v -> v.replace("-","").replace("+","")) + .map(v -> MapExplorer.getObjectFromPath(v, searchHitList.get(lastIndex).source())) + .map(v -> String.valueOf(v)) + .collect(Collectors.joining(",")); + }else{ + lastHitAfter = searchHitList.get(lastIndex).sort().stream().map(FieldValue::_toJsonString).collect(Collectors.joining(",")); + } LOGGER.debug("lastHitAfter="+lastHitAfter); } if (searchHitList.size() > 0 && sortParam != null && (beforeParam != null || sortParam.contains(collectionReference.params.idPath))) { previous = new Link(); previous.method = method; - firstHitAfter = searchHitList.get(0).sort().stream().map(FieldValue::_toJsonString).collect(Collectors.joining(",")); + //Warning the case where the sort contains geodistance and a no timestamp date is not covered + if(!sortParam.contains("geodistance")){ + // We can't use the sort() method because it transforms all the date in timestamp and dont keep the original format + firstHitAfter = Arrays.asList(sortParam.split(",")).stream() + .map(v -> v.replace("-","").replace("+","")) + .map(v -> MapExplorer.getObjectFromPath(v, searchHitList.get(0).source())) + .map(v -> String.valueOf(v)) + .collect(Collectors.joining(",")); + }else{ + firstHitAfter = searchHitList.get(0).sort().stream().map(FieldValue::_toJsonString).collect(Collectors.joining(",")); + } LOGGER.debug("firstHitAfter="+firstHitAfter); }