From 3c1255e8c261afd00f4797fd13f7a8fb5e5c1e57 Mon Sep 17 00:00:00 2001 From: Shiva Date: Wed, 6 Mar 2024 17:47:02 +0530 Subject: [PATCH 1/2] [Issue-789] Fixed Native Search doesn't return complete object issue --- .../sunbirdrc/registry/dao/SearchDaoImpl.java | 16 +++++++++++++--- .../registry/service/ISearchService.java | 4 +++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/dao/SearchDaoImpl.java b/java/registry/src/main/java/dev/sunbirdrc/registry/dao/SearchDaoImpl.java index f40e09eb6..a34e3ea70 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/dao/SearchDaoImpl.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/dao/SearchDaoImpl.java @@ -10,6 +10,8 @@ import dev.sunbirdrc.registry.middleware.util.Constants; import dev.sunbirdrc.registry.util.ReadConfigurator; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.function.BiPredicate; @@ -66,8 +68,12 @@ private GraphTraversal getFilteredResultTraversal( FilterOperators operator = filter.getOperator(); String path = filter.getPath(); - if (path != null) { - resultGraphTraversal = resultGraphTraversal.outE(path).inV(); + List subPaths = path != null + ? Arrays.asList(path.split("\\.")) + : new ArrayList<>(); + // Traverse into the sub paths + for (String subPath : subPaths) { + resultGraphTraversal = resultGraphTraversal.outE(subPath).inV(); } switch (operator) { @@ -135,7 +141,11 @@ private GraphTraversal getFilteredResultTraversal( resultGraphTraversal = resultGraphTraversal.has(property, P.eq(genericValue)); break; } - + // traverse back to the parent + Collections.reverse(subPaths); + for (String subPath : subPaths) { + resultGraphTraversal = resultGraphTraversal.inE(subPath).outV(); + } } } return resultGraphTraversal; diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/service/ISearchService.java b/java/registry/src/main/java/dev/sunbirdrc/registry/service/ISearchService.java index 220c660b4..89cab360b 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/service/ISearchService.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/service/ISearchService.java @@ -92,7 +92,9 @@ default void addToFilterList(String path, JsonNode inputQueryNode, List String operatorStr = entryValMap.getKey(); if (entryValMap.getValue().isObject()) { - addToFilterList(entry.getKey(), entryVal, filterList); + // accumulating the path as it goes deep in to the heirarachy if nested separating each level by a '.' + path = path == null ? entry.getKey() : path + "." + entry.getKey(); + addToFilterList(path, entryVal, filterList); } else { Object value = null; if (entryValMap.getValue().isArray()) { From e539ef1fa995f450049f1fe23e3845cacbfb291f Mon Sep 17 00:00:00 2001 From: Sreejit-K Date: Thu, 2 May 2024 11:34:00 +0530 Subject: [PATCH 2/2] multiple filters in the seach API fix --- .../java/dev/sunbirdrc/registry/service/ISearchService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/service/ISearchService.java b/java/registry/src/main/java/dev/sunbirdrc/registry/service/ISearchService.java index 89cab360b..f159f3c83 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/service/ISearchService.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/service/ISearchService.java @@ -93,8 +93,8 @@ default void addToFilterList(String path, JsonNode inputQueryNode, List if (entryValMap.getValue().isObject()) { // accumulating the path as it goes deep in to the heirarachy if nested separating each level by a '.' - path = path == null ? entry.getKey() : path + "." + entry.getKey(); - addToFilterList(path, entryVal, filterList); + String currpath = path == null ? entry.getKey() : path + "." + entry.getKey(); + addToFilterList(currpath, entryVal, filterList); } else { Object value = null; if (entryValMap.getValue().isArray()) {