Skip to content

Commit

Permalink
Fixed logic to make stats object lookups faster
Browse files Browse the repository at this point in the history
  • Loading branch information
synapticloop committed Sep 8, 2024
1 parent 4ea2d30 commit a5087dd
Showing 1 changed file with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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"));
}
}
}
Expand Down

0 comments on commit a5087dd

Please sign in to comment.