diff --git a/schemas/asset/1.0/schema.json b/schemas/asset/1.0/schema.json index 36ed2fcf0..f4fe326b1 100644 --- a/schemas/asset/1.0/schema.json +++ b/schemas/asset/1.0/schema.json @@ -1246,6 +1246,18 @@ "items": { "type": "string" } - } + }, + "taxonomyPaths_v2": { + "type": "array", + "items": { + "type": "object" + } + }, + "competencies_v3": { + "type": "array", + "items": { + "type": "object" + } + } } } diff --git a/schemas/collection/1.0/schema.json b/schemas/collection/1.0/schema.json index acc1b2569..279ce7bdb 100644 --- a/schemas/collection/1.0/schema.json +++ b/schemas/collection/1.0/schema.json @@ -1246,6 +1246,18 @@ "items": { "type": "string" } + }, + "taxonomyPaths_v2": { + "type": "array", + "items": { + "type": "object" + } + }, + "competencies_v3": { + "type": "array", + "items": { + "type": "object" + } } } } diff --git a/schemas/content/1.0/schema.json b/schemas/content/1.0/schema.json index ca889a75c..39e50c3e3 100644 --- a/schemas/content/1.0/schema.json +++ b/schemas/content/1.0/schema.json @@ -1347,6 +1347,18 @@ "items": { "type": "string" } - } + }, + "taxonomyPaths_v2": { + "type": "array", + "items": { + "type": "object" + } + }, + "competencies_v3": { + "type": "array", + "items": { + "type": "object" + } + } } } diff --git a/search-api/search-actors/src/main/java/org/sunbird/actors/SearchActor.java b/search-api/search-actors/src/main/java/org/sunbird/actors/SearchActor.java index c38b74b8a..e5f171083 100644 --- a/search-api/search-actors/src/main/java/org/sunbird/actors/SearchActor.java +++ b/search-api/search-actors/src/main/java/org/sunbird/actors/SearchActor.java @@ -242,8 +242,10 @@ private SearchDTO getSearchDTO(Request request) throws Exception { searchObj.setSortBy(sortBy); searchObj.setFacets(facets); searchObj.setProperties(properties); - if(multiFilters!=null) + if(multiFilters!=null){ multiFilterProperties.addAll(getSearchFilterProperties(multiFilters, wordChainsRequest)); + searchObj.setMultiFilterProperties(multiFilterProperties); + } // Added Implicit Filter Properties To Support Collection content tagging to reuse by tenants. setImplicitFilters(filters, searchObj); searchObj.setLimit(limit); diff --git a/search-api/search-core/src/main/java/org/sunbird/search/client/ElasticSearchUtil.java b/search-api/search-core/src/main/java/org/sunbird/search/client/ElasticSearchUtil.java index e0b96b19c..4929d205c 100644 --- a/search-api/search-core/src/main/java/org/sunbird/search/client/ElasticSearchUtil.java +++ b/search-api/search-core/src/main/java/org/sunbird/search/client/ElasticSearchUtil.java @@ -49,6 +49,7 @@ import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; +import org.elasticsearch.search.aggregations.bucket.nested.Nested; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.sunbird.common.Platform; import org.sunbird.common.exception.ServerException; @@ -613,43 +614,50 @@ private static SearchSourceBuilder buildJsonForWildCardQuery(String textKeyWord, @SuppressWarnings("unchecked") public static Object getCountFromAggregation(Aggregations aggregations, List> groupByList, - IESResultTransformer transformer) { - - Map countMap = new HashMap(); - if (aggregations != null) { - for (Map aggregationsMap : groupByList) { - Map parentCountMap = new HashMap(); - String groupByParent = (String) aggregationsMap.get("groupByParent"); - Terms terms = aggregations.get(groupByParent); - List> parentGroupList = new ArrayList>(); - List buckets = (List) terms.getBuckets(); - for (Bucket bucket : buckets) { - Map parentCountObject = new HashMap(); - parentCountObject.put("count", bucket.getDocCount()); - List groupByChildList = (List) aggregationsMap.get("groupByChildList"); - Aggregations subAggregations = bucket.getAggregations(); - if (null != groupByChildList && !groupByChildList.isEmpty() && null != subAggregations) { - Map groupByChildMap = new HashMap(); - for (String groupByChild : groupByChildList) { - Terms subTerms = subAggregations.get(groupByChild); - List childBuckets = (List) subTerms.getBuckets(); - Map childCountMap = new HashMap(); - for (Bucket childBucket : childBuckets) { - childCountMap.put(childBucket.getKeyAsString(), childBucket.getDocCount()); - groupByChildMap.put(groupByChild, childCountMap); - } - } - parentCountObject.putAll(groupByChildMap); - } - parentCountMap.put(bucket.getKeyAsString(), parentCountObject); - parentGroupList.add(parentCountMap); - } - - countMap.put(groupByParent, parentCountMap); - } - } - return transformer.getTransformedObject(countMap); - } + IESResultTransformer transformer) { + Map countMap = new HashMap(); + if (aggregations != null) { + for (Map aggregationsMap : groupByList) { + Map parentCountMap = new HashMap(); + String groupByParent = (String) aggregationsMap.get("groupByParent"); + Terms terms = null; + List buckets = null; + if (groupByParent.contains(".")) { + + Nested nested = aggregations.get(groupByParent.split("\\.")[0]); + terms = nested.getAggregations().get(groupByParent.split("\\.")[1]); + } else { + terms = aggregations.get(groupByParent); + } + buckets = (List)terms.getBuckets(); + List> parentGroupList = new ArrayList>(); + for (Bucket bucket : buckets) { + Map parentCountObject = new HashMap(); + parentCountObject.put("count", bucket.getDocCount()); + List groupByChildList = (List) aggregationsMap.get("groupByChildList"); + Aggregations subAggregations = bucket.getAggregations(); + if (null != groupByChildList && !groupByChildList.isEmpty() && null != subAggregations) { + Map groupByChildMap = new HashMap(); + for (String groupByChild : groupByChildList) { + Terms subTerms = subAggregations.get(groupByChild); + List childBuckets = (List) subTerms.getBuckets(); + Map childCountMap = new HashMap(); + for (Bucket childBucket : childBuckets) { + childCountMap.put(childBucket.getKeyAsString(), childBucket.getDocCount()); + groupByChildMap.put(groupByChild, childCountMap); + } + } + parentCountObject.putAll(groupByChildMap); + } + parentCountMap.put(bucket.getKeyAsString(), parentCountObject); + parentGroupList.add(parentCountMap); + } + + countMap.put(groupByParent, parentCountMap); + } + } + return transformer.getTransformedObject(countMap); + } private static void registerShutdownHook() { Runtime.getRuntime().addShutdownHook(new Thread() { @@ -711,4 +719,4 @@ public static void bulkDeleteDocumentById(String indexName, String documentType, } } -} \ No newline at end of file +} diff --git a/search-api/search-core/src/main/java/org/sunbird/search/processor/SearchProcessor.java b/search-api/search-core/src/main/java/org/sunbird/search/processor/SearchProcessor.java index 7b79d14ac..20ebdaf49 100644 --- a/search-api/search-core/src/main/java/org/sunbird/search/processor/SearchProcessor.java +++ b/search-api/search-core/src/main/java/org/sunbird/search/processor/SearchProcessor.java @@ -271,28 +271,53 @@ private SearchSourceBuilder processSearchQuery(SearchDTO searchDTO, List> groupByList, - SearchSourceBuilder searchSourceBuilder) { + @SuppressWarnings("unchecked") + private void setAggregations(List> groupByList, + SearchSourceBuilder searchSourceBuilder) { + TermsAggregationBuilder termBuilder = null; if (groupByList != null && !groupByList.isEmpty()) { - for (Map groupByMap : groupByList) { - String groupByParent = (String) groupByMap.get("groupByParent"); - termBuilder = AggregationBuilders.terms(groupByParent) - .field(groupByParent + SearchConstants.RAW_FIELD_EXTENSION) - .size(ElasticSearchUtil.defaultResultLimit); - List groupByChildList = (List) groupByMap.get("groupByChildList"); - if (groupByChildList != null && !groupByChildList.isEmpty()) { - for (String childGroupBy : groupByChildList) { - termBuilder.subAggregation(AggregationBuilders.terms(childGroupBy) - .field(childGroupBy + SearchConstants.RAW_FIELD_EXTENSION) - .size(ElasticSearchUtil.defaultResultLimit)); - } + HashMap> nestedAggregation = new HashMap<>(); + for (Map groupByMap : groupByList) { + String groupByParent = (String) groupByMap.get("groupByParent"); + if (!groupByParent.contains(".")) { + termBuilder = AggregationBuilders.terms(groupByParent) + .field(groupByParent + SearchConstants.RAW_FIELD_EXTENSION) + .size(ElasticSearchUtil.defaultResultLimit); + List groupByChildList = (List) groupByMap.get("groupByChildList"); + if (groupByChildList != null && !groupByChildList.isEmpty()) { + for (String childGroupBy : groupByChildList) { + termBuilder.subAggregation(AggregationBuilders.terms(childGroupBy) + .field(childGroupBy + SearchConstants.RAW_FIELD_EXTENSION) + .size(ElasticSearchUtil.defaultResultLimit)); } - searchSourceBuilder.aggregation(termBuilder); - } + } + searchSourceBuilder.aggregation(termBuilder); + } else { + if (nestedAggregation.get(groupByParent.split("\\.")[0]) != null) { + nestedAggregation.get(groupByParent.split("\\.")[0]).add(groupByParent.split("\\.")[1]); + } else { + List nestedAggrList = new ArrayList<>(); + nestedAggrList.add(groupByParent.split("\\.")[1]); + nestedAggregation.put(groupByParent.split("\\.")[0], nestedAggrList); + } + } + } + + if (!nestedAggregation.isEmpty()) { + for (Map.Entry> mapData : nestedAggregation.entrySet()) { + AggregationBuilder nestedAggregationBuilder = AggregationBuilders.nested(mapData.getKey(), mapData.getKey()); + for (String nestedValue : mapData.getValue()) { + termBuilder = AggregationBuilders.terms(nestedValue) + .field(mapData.getKey() + "." + nestedValue + SearchConstants.RAW_FIELD_EXTENSION) + .size(ElasticSearchUtil.defaultResultLimit); + nestedAggregationBuilder.subAggregation(termBuilder); + } + searchSourceBuilder.aggregation(nestedAggregationBuilder); + } + } } - } + } /** * @param searchDTO @@ -307,6 +332,8 @@ private QueryBuilder prepareSearchQuery(SearchDTO searchDTO) { formQuery(properties, queryBuilder, boolQuery, totalOperation); List multiFilterProperties = searchDTO.getMultiFilterProperties(); + System.out.println("multiFilterProperties:: "+multiFilterProperties); + if(multiFilterProperties!=null) formQuery(multiFilterProperties, queryBuilder, boolQuery, SearchConstants.SEARCH_OPERATION_OR);