diff --git a/src/main/java/de/mpg/imeji/logic/search/elasticsearch/factory/util/AggregationsParser.java b/src/main/java/de/mpg/imeji/logic/search/elasticsearch/factory/util/AggregationsParser.java index 17d4202d5..e7fd56e3c 100644 --- a/src/main/java/de/mpg/imeji/logic/search/elasticsearch/factory/util/AggregationsParser.java +++ b/src/main/java/de/mpg/imeji/logic/search/elasticsearch/factory/util/AggregationsParser.java @@ -1,9 +1,7 @@ package de.mpg.imeji.logic.search.elasticsearch.factory.util; import co.elastic.clients.elasticsearch._types.aggregations.*; -import co.elastic.clients.elasticsearch.core.SearchResponse; import co.elastic.clients.elasticsearch.core.search.ResponseBody; -import co.elastic.clients.json.JsonpUtils; import com.fasterxml.jackson.databind.node.ObjectNode; import de.mpg.imeji.logic.search.Search.SearchObjectTypes; import de.mpg.imeji.logic.search.elasticsearch.factory.ElasticAggregationFactory; @@ -40,67 +38,10 @@ private AggregationsParser() { * @return */ public static List parse(ResponseBody resp, SearchObjectTypes... types) { - /* - if (SearchObjectTypes.ITEM.equals(types[0])) { - return parseForItemFacets(resp); - } else if (SearchObjectTypes.COLLECTION.equals(types[0])) { - return parseForCollectionFacets(resp); - } - - - return new ArrayList(); - */ return parseForItemFacets(resp); } - /* - public static List parseForCollectionFacets(SearchResponse resp) { - LOGGER.info("Parse for collection facets"); - - - List facetResults = new ArrayList<>(); - if (resp != null && resp.getAggregations() != null) { - Nested metadata = resp.getAggregations().get("info"); - if (metadata != null) { - for (Aggregation mdAgg : metadata.getAggregations()) { - FacetResult facetResult = new FacetResult(getFacetName(mdAgg.getName()), mdAgg.getName()); - if (mdAgg instanceof Filter) { - Aggregation terms = ((Filter) mdAgg).getAggregations().asList().get(0); - fillResult(terms, facetResult); - } - - - facetResults.add(facetResult); - } - Filters system = resp.getAggregations().get("system"); - if (system != null) { - Bucket systemBucket = system.getBucketByKey("all"); - for (Aggregation agg : systemBucket.getAggregations()) { - FacetResult facetResult = new FacetResult(getFacetName(agg.getName()), agg.getName()); - if (agg instanceof Filters) { - for (Filters.Bucket bucket : ((Filters) agg).getBuckets()) { - facetResult.getValues().add(new FacetResultValue(bucket.getKeyAsString(), bucket.getDocCount())); - } - } else if (agg instanceof ParsedStringTerms) { - for (Terms.Bucket bucket : ((ParsedStringTerms) agg).getBuckets()) { - facetResult.getValues().add(new FacetResultValue(bucket.getKeyAsString(), bucket.getDocCount())); - } - - } - facetResults.add(facetResult); - } - } - - - - - - return facetResults; - - } - */ - public static List parseForItemFacets(ResponseBody resp) { List facetResults = new ArrayList<>(); @@ -111,7 +52,6 @@ public static List parseForItemFacets(ResponseBody resp FacetResult facetResult = new FacetResult(getFacetName(mdAgg.getKey()), mdAgg.getKey()); if (mdAgg.getValue().isFilter()) { Aggregate terms = mdAgg.getValue().filter().aggregations().values().iterator().next(); - //Aggregation terms = ((Filter) mdAgg).getAggregations().asList().get(0); fillResult(mdAgg.getKey(), terms, facetResult); } @@ -158,16 +98,11 @@ public static List parseForItemFacets(ResponseBody resp private static void fillResult(String key, Aggregate terms, FacetResult facetResult) { if (terms.isSterms()) { - for (Map.Entry bucket : terms.sterms().buckets().keyed().entrySet()) { - facetResult.getValues().add(new FacetResultValue(bucket.getKey(), bucket.getValue().docCount())); + for (StringTermsBucket bucket : terms.sterms().buckets().array()) { + facetResult.getValues().add(new FacetResultValue(bucket.key().stringValue(), bucket.docCount())); } - } /*else if (terms.isStats()) { - FacetResultValue result = new FacetResultValue(key, terms.stats().count()); - result.setMax(terms.stats().maxAsString()); - result.setMin(terms.stats().minAsString()); - facetResult.getValues().add(result); - }*/ + } else if (terms.isStats()) { FacetResultValue result = new FacetResultValue(key, terms.stats().count()); double max = terms.stats().max();