diff --git a/src/main/java/com/synapticloop/panl/server/handler/CollectionRequestHandler.java b/src/main/java/com/synapticloop/panl/server/handler/CollectionRequestHandler.java index f4f258c4..bc05a68b 100644 --- a/src/main/java/com/synapticloop/panl/server/handler/CollectionRequestHandler.java +++ b/src/main/java/com/synapticloop/panl/server/handler/CollectionRequestHandler.java @@ -339,23 +339,17 @@ private String parseResponse( panlObject.put(JSON_KEY_AVAILABLE, availableProcessor.processToObject(panlTokenMap, response)); - // now we are going to add the dynamic range if they exist JSONObject statsObject = solrJsonObject.optJSONObject("stats"); if(null != statsObject) { JSONObject statsFieldObjects = statsObject.optJSONObject("stats_fields"); - if(null != statsFieldObjects) { - Iterator keys = statsFieldObjects.keys(); - while(keys.hasNext()) { - String key = keys.next(); - JSONObject valueObject = statsFieldObjects.getJSONObject(key); - // now that we have the value, go through the range facets and get the right one. - JSONArray jsonArray = panlObject.getJSONObject(JSON_KEY_AVAILABLE).getJSONArray(Processor.JSON_KEY_RANGE_FACETS); - for(Object object : jsonArray) { - JSONObject rangeObject = (JSONObject) object; - if(rangeObject.getString("facet_name").equals(key)) { - rangeObject.put(JSON_KEY_DYNAMIC_MIN, valueObject.getInt("min")); - rangeObject.put(JSON_KEY_DYNAMIC_MAX, valueObject.getInt("max")); - } + if (null != statsFieldObjects) { + JSONArray jsonArray = panlObject.getJSONObject(JSON_KEY_AVAILABLE).getJSONArray(Processor.JSON_KEY_RANGE_FACETS); + for (Object object : jsonArray) { + JSONObject rangeObject = (JSONObject) object; + String facetName = rangeObject.getString("facet_name"); + if(null != statsFieldObjects.optJSONObject(facetName, null)) { + rangeObject.put(JSON_KEY_DYNAMIC_MIN, statsFieldObjects.getJSONObject(facetName).getInt("min")); + rangeObject.put(JSON_KEY_DYNAMIC_MAX, statsFieldObjects.getJSONObject(facetName).getInt("max")); } } }