docs: @SuppressWarnings("unchecked")
    public void finishStage(ResponseBuilder rb) {
      if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) {
        if (rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY
            && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) {
          for (ShardRequest sreq : rb.finished) {
            if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
                && sreq.params.getBool(PARAM_MTAS_TERMVECTOR, false)) {
              for (ShardResponse shardResponse : sreq.responses) {
                NamedList<Object> response = shardResponse.getSolrResponse()
                    .getResponse();
                try {
                  ArrayList<NamedList<Object>> data = (ArrayList<NamedList<Object>>) response
                      .findRecursive("mtas", NAME);
                  if (data != null) {
                    MtasSolrResultUtil.decode(data);
                  }
                } catch (ClassCastException e) {
                  log.debug(e);
                  // shouldnt happen
                }
              }
            }
          }
          if (rb.stage == MtasSolrSearchComponent.STAGE_TERMVECTOR_FINISH) {
            if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS,
                false)
                && rb.req.getParams().getBool(PARAM_MTAS_TERMVECTOR, false)) {
              Set<String> ids = MtasSolrResultUtil.getIdsFromParameters(
                  rb.req.getParams(), PARAM_MTAS_TERMVECTOR);
              if (!ids.isEmpty()) {
                int tmpCounter = 0;
                String[] keys = new String[ids.size()];
                String[] numbers = new String[ids.size()];
                for (String id : ids) {
                  keys[tmpCounter] = rb.req.getParams()
                      .get(
                          PARAM_MTAS_TERMVECTOR + "." + id + "."
                              + NAME_MTAS_TERMVECTOR_KEY,
                          String.valueOf(tmpCounter))
                      .trim();
                  numbers[tmpCounter] = rb.req.getParams()
                      .get(PARAM_MTAS_TERMVECTOR + "." + id + "."
                          + NAME_MTAS_TERMVECTOR_NUMBER, null);
                  tmpCounter++;
                }
                // mtas response
                NamedList<Object> mtasResponse = null;
                try {
                  mtasResponse = (NamedList<Object>) rb.rsp.getValues()
                      .get("mtas");
                } catch (ClassCastException e) {
                  log.debug(e);
                  mtasResponse = null;
                }
                if (mtasResponse == null) {
                  mtasResponse = new SimpleOrderedMap<>();
                  rb.rsp.add("mtas", mtasResponse);
                }
                Object o = mtasResponse.get(NAME);
                if (o != null && o instanceof ArrayList) {
                  ArrayList<?> tvList = (ArrayList<?>) o;
                  for (int i = 0; i < tmpCounter; i++) {
                    for (int j = 0; j < tvList.size(); j++) {
                      NamedList<Object> item = (NamedList<Object>) tvList.get(j);
                      boolean condition;
                      condition = item != null;
                      condition &= item.get("key") != null;
                      condition &= item.get("key") instanceof String;
                      condition &= item.get("list") != null;
                      condition &= item.get("list") instanceof ArrayList;
                      if (condition) {
                        String key = (String) item.get("key");
                        ArrayList<Object> list = (ArrayList<Object>) item
                            .get("list");
                        if (key.equals(keys[i])) {
                          int number;
                          if (numbers[i] != null) {
                            int numberValue = Integer.parseInt(numbers[i]);
                            number = numberValue >= 0 ? numberValue
                                : Integer.MAX_VALUE;
                          } else {
                            number = DEFAULT_NUMBER;
                          }
                          if (list.size() > number) {
                            item.removeAll("list");
                            item.add("list", list.subList(0, number));
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }