docs: @SuppressWarnings({ "rawtypes", "unchecked" })
    private static void rewrite(NamedList<Object> nl,
        MtasSolrSearchComponent searchComponent, boolean doCollapse)
        throws IOException {
      boolean showDebugInfo = false;
      HashMap<String, NamedList<Object>> collapseNamedList = new HashMap<>();
      int length = nl.size();
      for (int i = 0; i < length; i++) {
        if (nl.getVal(i) instanceof NamedList) {
          NamedList o = (NamedList) nl.getVal(i);
          rewrite(o, searchComponent, true);
          nl.setVal(i, o);
        } else if (nl.getVal(i) instanceof ArrayList) {
          ArrayList o = (ArrayList) nl.getVal(i);
          rewrite(o, searchComponent);
          nl.setVal(i, o);
        } else if (nl.getVal(i) instanceof MtasDataItem) {
          MtasDataItem dataItem = (MtasDataItem) nl.getVal(i);
          nl.setVal(i, dataItem.rewrite(showDebugInfo));
        } else if (nl.getVal(i) instanceof MtasSolrCollectionResult) {
          MtasSolrCollectionResult o = (MtasSolrCollectionResult) nl.getVal(i);
          collapseNamedList.put(nl.getName(i), o.rewrite(searchComponent));
        } else if (nl.getVal(i) instanceof MtasSolrMtasResult) {
          MtasSolrMtasResult o = (MtasSolrMtasResult) nl.getVal(i);
          if (o.dataCollector.getCollectorType()
              .equals(DataCollector.COLLECTOR_TYPE_LIST)) {
            if (!o.dataCollector.withTotal()) {
              NamedList<Object> nnl = o.getNamedList(showDebugInfo);
              for (int j = 0; j < nnl.size(); j++) {
                if (nnl.getVal(j) != null
                    && nnl.getVal(j) instanceof MtasDataItem) {
                  MtasDataItem mdi = (MtasDataItem) nnl.getVal(j);
                  mdi.rewrite(showDebugInfo);
                  nnl.setVal(j, mdi);
                }
              }
              // System.out.println("rewrite -- "+nnl);
              nl.setVal(i, rewriteToArray(nnl));
              // System.out.println("rewrite! "+nl.getVal(i));
            } else {
              NamedList<Object> tmpResponse = new SimpleOrderedMap<>();
              tmpResponse.add(nl.getName(i) + "Total", o.dataCollector.getSize());
              NamedList<Object> nnl = o.getNamedList(showDebugInfo);
              for (int j = 0; j < nnl.size(); j++) {
                if (nnl.getVal(j) != null
                    && nnl.getVal(j) instanceof MtasDataItem) {
                  MtasDataItem mdi = (MtasDataItem) nnl.getVal(j);
                  mdi.rewrite(showDebugInfo);
                  nnl.setVal(j, mdi);
                }
              }
              tmpResponse.add(nl.getName(i), rewriteToArray(nnl));
              nl.setVal(i, null);
              collapseNamedList.put(nl.getName(i), tmpResponse);
            }
          } else if (o.dataCollector.getCollectorType()
              .equals(DataCollector.COLLECTOR_TYPE_DATA)) {
            NamedList<Object> nnl = o.getData(showDebugInfo);
            if (nnl.size() > 0) {
              rewrite(nnl, searchComponent);
              collapseNamedList.put(nl.getName(i), nnl);
              nl.setVal(i, nnl);
            } else {
              nl.setVal(i, null);
            }
          }
        }
      }
      // collapse
      if (doCollapse && collapseNamedList.size() > 0) {
        for (String key : collapseNamedList.keySet()) {
          nl.remove(key);
        }
        for (NamedList<Object> items : collapseNamedList.values()) {
          nl.addAll(items);
        }
      }
    }