Prepare positions.

@param rb the rb
@param mtasFields the mtas fields
@throws IOException Signals that an I/O exception has occurred.
181442
private void preparePositions(ResponseBuilder rb, ComponentFields mtasFields)
      throws IOException {
    Set<String> ids = MtasSolrResultUtil
        .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_STATS_POSITIONS);
    if (!ids.isEmpty()) {
      int tmpCounter = 0;
      String[] fields = new String[ids.size()];
      String[] keys = new String[ids.size()];
      String[] minima = new String[ids.size()];
      String[] maxima = new String[ids.size()];
      String[] types = new String[ids.size()];
      for (String id : ids) {
        fields[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_POSITIONS
            + "." + id + "." + NAME_MTAS_STATS_POSITIONS_FIELD, null);
        keys[tmpCounter] = rb.req.getParams()
            .get(PARAM_MTAS_STATS_POSITIONS + "." + id + "."
                + NAME_MTAS_STATS_POSITIONS_KEY, String.valueOf(tmpCounter))
            .trim();
        minima[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_POSITIONS
            + "." + id + "." + NAME_MTAS_STATS_POSITIONS_MINIMUM, null);
        maxima[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_POSITIONS
            + "." + id + "." + NAME_MTAS_STATS_POSITIONS_MAXIMUM, null);
        types[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_POSITIONS
            + "." + id + "." + NAME_MTAS_STATS_POSITIONS_TYPE, null);
        tmpCounter++;
      }
      String uniqueKeyField = rb.req.getSchema().getUniqueKeyField().getName();
      mtasFields.doStats = true;
      mtasFields.doStatsPositions = true;
      rb.setNeedDocSet(true);
      for (String field : fields) {
        if (field == null || field.isEmpty()) {
          throw new IOException("no (valid) field in mtas stats positions");
        } else if (!mtasFields.list.containsKey(field)) {
          mtasFields.list.put(field, new ComponentField(uniqueKeyField));
        }
      }
      MtasSolrResultUtil.compareAndCheck(keys, fields,
          NAME_MTAS_STATS_POSITIONS_KEY, NAME_MTAS_STATS_POSITIONS_FIELD, true);
      MtasSolrResultUtil.compareAndCheck(minima, fields,
          NAME_MTAS_STATS_POSITIONS_MINIMUM, NAME_MTAS_STATS_POSITIONS_FIELD,
          false);
      MtasSolrResultUtil.compareAndCheck(maxima, fields,
          NAME_MTAS_STATS_POSITIONS_MAXIMUM, NAME_MTAS_STATS_POSITIONS_FIELD,
          false);
      MtasSolrResultUtil.compareAndCheck(types, fields,
          NAME_MTAS_STATS_POSITIONS_TYPE, NAME_MTAS_STATS_POSITIONS_FIELD,
          false);
      for (int i = 0; i < fields.length; i++) {
        String field = fields[i];
        String key = keys[i];
        String type = (types[i] == null) || (types[i].isEmpty()) ? null
            : types[i].trim();
        Double minimum = (minima[i] == null) || (minima[i].isEmpty()) ? null
            : Double.parseDouble(minima[i]);
        Double maximum = (maxima[i] == null) || (maxima[i].isEmpty()) ? null
            : Double.parseDouble(maxima[i]);
        try {
          mtasFields.list.get(field).statsPositionList
              .add(new ComponentPosition(key, minimum, maximum, type));
        } catch (ParseException e) {
          throw new IOException(e.getMessage());
        }
      }
    }
  }
935546
private void position(long newPosition) throws IOException {

        check();
        checkPosition(newPosition);
        this.getRandomAccessFile().seek(newPosition + getHeaderLength());
    }
1308768
public void readFields(DataInput in) throws IOException {
        t.readFields(in);
        position = in.readInt();
    }
727016
public void prepare(ResponseBuilder rb, ComponentFields mtasFields)
      throws IOException {
    // System.out.println(
    // "collection: " + System.nanoTime() + " - " +
    // Thread.currentThread().getId()
    // + " - " + rb.req.getParams().getBool("isShard", false) + " PREPARE "
    // + rb.stage + " " + rb.req.getParamString());
    Set<String> ids = MtasSolrResultUtil
        .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_COLLECTION);
    if (!ids.isEmpty()) {
      int tmpCounter = 0;
      String[] keys = new String[ids.size()];
      String[] versions = new String[ids.size()];
      String[] actions = new String[ids.size()];
      String[] fields = new String[ids.size()];
      String[] collectionIds = new String[ids.size()];
      String[] posts = new String[ids.size()];
      String[] urls = new String[ids.size()];
      String[] collections = new String[ids.size()];
      for (String id : ids) {
        actions[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_COLLECTION + "."
            + id + "." + NAME_MTAS_COLLECTION_ACTION, null);
        keys[tmpCounter] = rb.req.getParams().get(
            PARAM_MTAS_COLLECTION + "." + id + "." + NAME_MTAS_COLLECTION_KEY,
            String.valueOf(tmpCounter)).trim();
        versions[tmpCounter] = rb.req.getParams().get(
            PARAM_MTAS_COLLECTION + "." + id + "." + NAME_MTAS_COLLECTION_VERSION,
            null);
        fields[tmpCounter] = rb.req.getParams().get(
            PARAM_MTAS_COLLECTION + "." + id + "." + NAME_MTAS_COLLECTION_FIELD,
            null);
        collectionIds[tmpCounter] = rb.req.getParams().get(
            PARAM_MTAS_COLLECTION + "." + id + "." + NAME_MTAS_COLLECTION_ID,
            null);
        posts[tmpCounter] = rb.req.getParams().get(
            PARAM_MTAS_COLLECTION + "." + id + "." + NAME_MTAS_COLLECTION_POST,
            null);
        urls[tmpCounter] = rb.req.getParams().get(
            PARAM_MTAS_COLLECTION + "." + id + "." + NAME_MTAS_COLLECTION_URL,
            null);
        collections[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_COLLECTION
            + "." + id + "." + NAME_MTAS_COLLECTION_COLLECTION, null);
        // always id for post
        if (actions[tmpCounter] != null && (actions[tmpCounter]
            .equals(ComponentCollection.ACTION_POST)
            || actions[tmpCounter].equals(ComponentCollection.ACTION_IMPORT)
            || actions[tmpCounter].equals(ComponentCollection.ACTION_CREATE))) {
          if (collectionIds[tmpCounter] == null
              || collectionIds[tmpCounter].isEmpty()) {
            collectionIds[tmpCounter] = UUID.randomUUID().toString();
            ModifiableSolrParams changedParams = new ModifiableSolrParams(
                rb.req.getParams());
            changedParams.remove(PARAM_MTAS_COLLECTION + "." + id + "."
                + NAME_MTAS_COLLECTION_ID);
            changedParams.set(PARAM_MTAS_COLLECTION + "." + id + "."
                + NAME_MTAS_COLLECTION_ID, collectionIds[tmpCounter]);
            rb.req.setParams(changedParams);
          }
        }
        tmpCounter++;
      }
      mtasFields.doCollection = true;
      MtasSolrResultUtil.compareAndCheck(keys, actions,
          NAME_MTAS_COLLECTION_KEY, NAME_MTAS_COLLECTION_ACTION, true);
      MtasSolrResultUtil.compareAndCheck(keys, versions,
          NAME_MTAS_COLLECTION_KEY, NAME_MTAS_COLLECTION_VERSION, true);
      MtasSolrResultUtil.compareAndCheck(keys, fields, NAME_MTAS_COLLECTION_KEY,
          NAME_MTAS_COLLECTION_FIELD, false);
      MtasSolrResultUtil.compareAndCheck(keys, collectionIds,
          NAME_MTAS_COLLECTION_KEY, NAME_MTAS_COLLECTION_ID, false);
      MtasSolrResultUtil.compareAndCheck(keys, posts, NAME_MTAS_COLLECTION_KEY,
          NAME_MTAS_COLLECTION_POST, false);
      MtasSolrResultUtil.compareAndCheck(keys, urls, NAME_MTAS_COLLECTION_KEY,
          NAME_MTAS_COLLECTION_URL, false);
      MtasSolrResultUtil.compareAndCheck(keys, collections,
          NAME_MTAS_COLLECTION_KEY, NAME_MTAS_COLLECTION_COLLECTION, false);
      for (int i = 0; i < actions.length; i++) {
        if (actions[i] != null) {
          ComponentCollection componentCollection;
          switch (actions[i]) {
          case ComponentCollection.ACTION_LIST:
            componentCollection = new ComponentCollection(keys[i],
                ComponentCollection.ACTION_LIST);
            componentCollection.setListVariables();
            mtasFields.collection.add(componentCollection);
            break;
          case ComponentCollection.ACTION_CHECK:
            if (collectionIds[i] != null) {
              componentCollection = new ComponentCollection(keys[i],
                  ComponentCollection.ACTION_CHECK);
              componentCollection.setCheckVariables(collectionIds[i]);
              mtasFields.collection.add(componentCollection);
            } else {
              throw new IOException(
                  "no id defined for collection (" + actions[i] + ")");
            }
            break;
          case ComponentCollection.ACTION_GET:
            if (collectionIds[i] != null) {
              componentCollection = new ComponentCollection(keys[i],
                  ComponentCollection.ACTION_GET);
              componentCollection.setGetVariables(collectionIds[i]);
              mtasFields.collection.add(componentCollection);
            } else {
              throw new IOException(
                  "no id defined for collection (" + actions[i] + ")");
            }
            break;
          case ComponentCollection.ACTION_CREATE:
            if (collectionIds[i] == null) {
              collectionIds[i] = UUID.randomUUID().toString();
            }
            if (fields[i] != null) {
              Set<String> fieldList = new HashSet<>(
                  Arrays.asList(fields[i].split(",")));
              componentCollection = new ComponentCollection(keys[i],
                  ComponentCollection.ACTION_CREATE);
              componentCollection.setCreateVariables(collectionIds[i],
                  fieldList);
              mtasFields.doCollection = true;
              mtasFields.collection.add(componentCollection);
              rb.setNeedDocSet(true);
            } else {
              throw new IOException(
                  "no field defined for collection (" + actions[i] + ")");
            }
            break;
          case ComponentCollection.ACTION_POST:
            if (posts[i] != null) {
              componentCollection = new ComponentCollection(keys[i],
                  ComponentCollection.ACTION_POST);
              componentCollection.setPostVariables(collectionIds[i],
                  stringToStringValues(posts[i]), versions[i]);
              mtasFields.collection.add(componentCollection);
            } else {
              throw new IOException(
                  "no post defined for collection (" + actions[i] + ")");
            }
            break;
          case ComponentCollection.ACTION_IMPORT:
            if (urls[i] != null && collections[i] != null) {
              componentCollection = new ComponentCollection(keys[i],
                  ComponentCollection.ACTION_IMPORT);
              componentCollection.setImportVariables(collectionIds[i], urls[i],
                  collections[i]);
              mtasFields.collection.add(componentCollection);
            } else {
              throw new IOException(
                  "no url or collection defined for collection (" + actions[i]
                      + ")");
            }
            break;
          case ComponentCollection.ACTION_DELETE:
            if (collectionIds[i] != null) {
              componentCollection = new ComponentCollection(keys[i],
                  ComponentCollection.ACTION_DELETE);
              componentCollection.setDeleteVariables(collectionIds[i]);
              mtasFields.collection.add(componentCollection);
            } else {
              throw new IOException(
                  "no id defined for collection (" + actions[i] + ")");
            }
            break;
          case ComponentCollection.ACTION_EMPTY:
            componentCollection = new ComponentCollection(keys[i],
                ComponentCollection.ACTION_EMPTY);
            mtasFields.collection.add(componentCollection);
            break;
          default:
            throw new IOException(
                "unrecognized action '" + actions[i] + "' for collection");
          }
        } else {
          throw new IOException("no action defined for collection");
        }
      }
    }
  }
744338
protected void position(int newPosition)
  {
    if (tc.isEntryEnabled()) Tr.entry(tc, "position", new Object[]{this,new Integer(newPosition)});

    newPosition -= _absolutePosition;
    _buffer.position(newPosition);

    if (tc.isEntryEnabled()) Tr.exit(tc, "position");
  }
631315
public void prepare(ResponseBuilder rb, ComponentFields mtasFields)
      throws IOException {
    Set<String> ids = MtasSolrResultUtil
        .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_LIST);
    if (!ids.isEmpty()) {
      int tmpCounter = 0;
      String[] fields = new String[ids.size()];
      String[] queryTypes = new String[ids.size()];
      String[] queryValues = new String[ids.size()];
      String[] queryPrefixes = new String[ids.size()];
      HashMap<String, String[]>[] queryVariables = new HashMap[ids.size()];
      String[] queryIgnores = new String[ids.size()];
      String[] queryMaximumIgnoreLengths = new String[ids.size()];
      String[] keys = new String[ids.size()];
      String[] prefixes = new String[ids.size()];
      String[] starts = new String[ids.size()];
      String[] numbers = new String[ids.size()];
      String[] lefts = new String[ids.size()];
      String[] rights = new String[ids.size()];
      String[] outputs = new String[ids.size()];
      for (String id : ids) {
        fields[tmpCounter] = rb.req.getParams()
            .get(PARAM_MTAS_LIST + "." + id + "." + NAME_MTAS_LIST_FIELD, null);
        keys[tmpCounter] = rb.req.getParams()
            .get(PARAM_MTAS_LIST + "." + id + "." + NAME_MTAS_LIST_KEY,
                String.valueOf(tmpCounter))
            .trim();
        queryTypes[tmpCounter] = rb.req.getParams().get(
            PARAM_MTAS_LIST + "." + id + "." + NAME_MTAS_LIST_QUERY_TYPE, null);
        queryValues[tmpCounter] = rb.req.getParams().get(
            PARAM_MTAS_LIST + "." + id + "." + NAME_MTAS_LIST_QUERY_VALUE,
            null);
        queryPrefixes[tmpCounter] = rb.req.getParams().get(
            PARAM_MTAS_LIST + "." + id + "." + NAME_MTAS_LIST_QUERY_PREFIX,
            null);
        queryIgnores[tmpCounter] = rb.req.getParams().get(
            PARAM_MTAS_LIST + "." + id + "." + NAME_MTAS_LIST_QUERY_IGNORE,
            null);
        queryMaximumIgnoreLengths[tmpCounter] = rb.req.getParams()
            .get(PARAM_MTAS_LIST + "." + id + "."
                + NAME_MTAS_LIST_QUERY_MAXIMUM_IGNORE_LENGTH, null);
        Set<String> vIds = MtasSolrResultUtil.getIdsFromParameters(
            rb.req.getParams(),
            PARAM_MTAS_LIST + "." + id + "." + NAME_MTAS_LIST_QUERY_VARIABLE);
        queryVariables[tmpCounter] = new HashMap<>();
        if (!vIds.isEmpty()) {
          HashMap<String, ArrayList<String>> tmpVariables = new HashMap<>();
          for (String vId : vIds) {
            String name = rb.req.getParams().get(
                PARAM_MTAS_LIST + "." + id + "." + NAME_MTAS_LIST_QUERY_VARIABLE
                    + "." + vId + "." + SUBNAME_MTAS_LIST_QUERY_VARIABLE_NAME,
                null);
            if (name != null) {
              if (!tmpVariables.containsKey(name)) {
                tmpVariables.put(name, new ArrayList<String>());
              }
              String value = rb.req.getParams()
                  .get(PARAM_MTAS_LIST + "." + id + "."
                      + NAME_MTAS_LIST_QUERY_VARIABLE + "." + vId + "."
                      + SUBNAME_MTAS_LIST_QUERY_VARIABLE_VALUE, null);
              if (value != null) {
                ArrayList<String> list = new ArrayList<>();
                String[] subList = value.split("(?<!\\\\),");
                for (int i = 0; i < subList.length; i++) {
                  list.add(
                      subList[i].replace("\\,", ",").replace("\\\\", "\\"));
                }
                tmpVariables.get(name).addAll(list);
              }
            }
          }
          for (Entry<String, ArrayList<String>> entry : tmpVariables
              .entrySet()) {
            queryVariables[tmpCounter].put(entry.getKey(),
                entry.getValue().toArray(new String[entry.getValue().size()]));
          }
        }
        prefixes[tmpCounter] = rb.req.getParams().get(
            PARAM_MTAS_LIST + "." + id + "." + NAME_MTAS_LIST_PREFIX, null);
        starts[tmpCounter] = rb.req.getParams()
            .get(PARAM_MTAS_LIST + "." + id + "." + NAME_MTAS_LIST_START, null);
        numbers[tmpCounter] = rb.req.getParams().get(
            PARAM_MTAS_LIST + "." + id + "." + NAME_MTAS_LIST_NUMBER, null);
        lefts[tmpCounter] = rb.req.getParams()
            .get(PARAM_MTAS_LIST + "." + id + "." + NAME_MTAS_LIST_LEFT, null);
        rights[tmpCounter] = rb.req.getParams()
            .get(PARAM_MTAS_LIST + "." + id + "." + NAME_MTAS_LIST_RIGHT, null);
        outputs[tmpCounter] = rb.req.getParams().get(
            PARAM_MTAS_LIST + "." + id + "." + NAME_MTAS_LIST_OUTPUT, null);
        tmpCounter++;
      }
      String uniqueKeyField = rb.req.getSchema().getUniqueKeyField().getName();
      mtasFields.doList = true;
      rb.setNeedDocSet(true);
      for (String field : fields) {
        if (field == null || field.isEmpty()) {
          throw new IOException("no (valid) field in mtas list");
        } else if (!mtasFields.list.containsKey(field)) {
          mtasFields.list.put(field, new ComponentField(uniqueKeyField));
        }
      }
      MtasSolrResultUtil.compareAndCheck(keys, fields, NAME_MTAS_LIST_KEY,
          NAME_MTAS_LIST_FIELD, true);
      MtasSolrResultUtil.compareAndCheck(prefixes, queryValues,
          NAME_MTAS_LIST_QUERY_VALUE, NAME_MTAS_LIST_FIELD, false);
      MtasSolrResultUtil.compareAndCheck(prefixes, queryTypes,
          NAME_MTAS_LIST_QUERY_TYPE, NAME_MTAS_LIST_FIELD, false);
      MtasSolrResultUtil.compareAndCheck(prefixes, queryPrefixes,
          NAME_MTAS_LIST_QUERY_PREFIX, NAME_MTAS_LIST_FIELD, false);
      MtasSolrResultUtil.compareAndCheck(prefixes, queryIgnores,
          NAME_MTAS_LIST_QUERY_IGNORE, NAME_MTAS_LIST_FIELD, false);
      MtasSolrResultUtil.compareAndCheck(prefixes, queryMaximumIgnoreLengths,
          NAME_MTAS_LIST_QUERY_MAXIMUM_IGNORE_LENGTH, NAME_MTAS_LIST_FIELD,
          false);
      MtasSolrResultUtil.compareAndCheck(prefixes, fields,
          NAME_MTAS_LIST_PREFIX, NAME_MTAS_LIST_FIELD, false);
      MtasSolrResultUtil.compareAndCheck(starts, fields, NAME_MTAS_LIST_START,
          NAME_MTAS_LIST_FIELD, false);
      MtasSolrResultUtil.compareAndCheck(numbers, fields, NAME_MTAS_LIST_NUMBER,
          NAME_MTAS_LIST_FIELD, false);
      MtasSolrResultUtil.compareAndCheck(lefts, fields, NAME_MTAS_LIST_LEFT,
          NAME_MTAS_LIST_FIELD, false);
      MtasSolrResultUtil.compareAndCheck(rights, fields, NAME_MTAS_LIST_RIGHT,
          NAME_MTAS_LIST_FIELD, false);
      MtasSolrResultUtil.compareAndCheck(outputs, fields, NAME_MTAS_LIST_OUTPUT,
          NAME_MTAS_LIST_FIELD, false);
      for (int i = 0; i < fields.length; i++) {
        ComponentField cf = mtasFields.list.get(fields[i]);
        Integer maximumIgnoreLength = (queryMaximumIgnoreLengths[i] == null)
            ? null : Integer.parseInt(queryMaximumIgnoreLengths[i]);
        MtasSpanQuery q = MtasSolrResultUtil.constructQuery(queryValues[i],
            queryTypes[i], queryPrefixes[i], queryVariables[i], fields[i],
            queryIgnores[i], maximumIgnoreLength);
        // minimize number of queries
        if (cf.spanQueryList.contains(q)) {
          q = cf.spanQueryList.get(cf.spanQueryList.indexOf(q));
        } else {
          cf.spanQueryList.add(q);
        }
        String key = (keys[i] == null) || (keys[i].isEmpty())
            ? String.valueOf(i) + ":" + fields[i] + ":" + queryValues[i] + ":"
                + queryPrefixes[i]
            : keys[i].trim();
        String prefix = prefixes[i];
        int start = (starts[i] == null) || (starts[i].isEmpty()) ? 0
            : Integer.parseInt(starts[i]);
        int number = (numbers[i] == null) || (numbers[i].isEmpty()) ? 10
            : Integer.parseInt(numbers[i]);
        int left = (lefts[i] == null) || lefts[i].isEmpty() ? 0
            : Integer.parseInt(lefts[i]);
        int right = (rights[i] == null) || rights[i].isEmpty() ? 0
            : Integer.parseInt(rights[i]);
        String output = outputs[i];
        mtasFields.list.get(fields[i]).listList.add(new ComponentList(q,
            fields[i], queryValues[i], queryTypes[i], queryPrefixes[i],
            queryVariables[i], queryIgnores[i], queryMaximumIgnoreLengths[i],
            key, prefix, start, number, left, right, output));
      }
    }
  }
1025697
public FieldList move(int iRelPosition) throws DBException
    {
        if (this.getRecord() != this.getCurrentTable().getRecord())
        {
        	if (this.getRecord().getEditMode() == DBConstants.EDIT_CURRENT)
        	{
	        	this.getRecord().getKeyArea(DBConstants.MAIN_KEY_AREA).reverseKeyBuffer(null, DBConstants.TEMP_KEY_AREA);
	        	this.getRecord().getKeyArea().reverseKeyBuffer(null, DBConstants.TEMP_KEY_AREA);	// Restore key (since this is current, it is guaranteed not to be next)
        	}
        }
    	Record recLastCurrent = this.getCurrentTable().getRecord();
        FieldList record = this.moveThruMultipleTables(iRelPosition);
    	if (this.getRecord() != record)
        {
            if (this.getRecord() == recLastCurrent)
            {
            	this.getRecord().getKeyArea().setupKeyBuffer(null, DBConstants.TEMP_KEY_AREA);	// Save this for compare later
	        	this.getRecord().getKeyArea(DBConstants.MAIN_KEY_AREA).reverseKeyBuffer(null, DBConstants.TEMP_KEY_AREA);
            }
            this.syncRecordToBase(this.getRecord(), (Record)record, false);
        }
    	else
    	{
            if (this.getRecord() != recLastCurrent)
            {	// The record was lost when I synced it
            	Object bookmark = this.getRecord().getHandle(DBConstants.BOOKMARK_HANDLE);
            	this.getRecord().setHandle(bookmark, DBConstants.BOOKMARK_HANDLE);
            }
    	}
        return (record == null) ? null : this.getRecord();
    }
1352546
private void processCharacters(final Characters paramText) throws IOException, XMLStreamException,
        TTException {
        assert paramText != null;
        // Initialize variables.
        initializeVars();
        final String text = paramText.getData().toString();
        if (!text.isEmpty()) {
            // Main algorithm to determine if same, insert or a delete has to be
            // made.
            algorithm(paramText);

            if (mFound && mIsRightSibling) {
                /*
                 * Cannot happen because if text node after end tag get's
                 * deleted it's done already while parsing the end tag. If text
                 * node should be deleted at the top of a subtree (right after a
                 * start tag has been parsed) it's done in
                 * processStartTag(StartElement).
                 */
                // mDelete = EDelete.ATSTARTMIDDLE;
                // deleteNode();
                throw new AssertionError("");
            } else if (!mFound) {
                insertTextNode(paramText);
            } else if (mFound) {
                sameTextNode();
            }
        }
    }
1087989
private void prepareColumn(ThriftRow tr, EntityMetadata m, Object value, byte[] name, long timestamp, int ttl)
    {
        if (value != null)
        {
            if (m.isCounterColumnType())
            {
                CounterColumn counterColumn = prepareCounterColumn((String) value, name);
                tr.addCounterColumn(counterColumn);
            }
            else
            {
                Column column = prepareColumn((byte[]) value, name, timestamp, ttl);
                tr.addColumn(column);
            }
        }
    }
933284
private void distributedProcessMissingKey(ResponseBuilder rb,
      ComponentFields mtasFields) throws IOException {
    HashMap<String, HashMap<String, HashSet<String>>> missingTermvectorKeys = computeMissingTermvectorItemsPerShard(
        rb.finished, "mtas", NAME);
    for (Entry<String, HashMap<String, HashSet<String>>> entry : missingTermvectorKeys
        .entrySet()) {
      HashMap<String, HashSet<String>> missingTermvectorKeysShard = entry
          .getValue();
      ModifiableSolrParams paramsNewRequest = new ModifiableSolrParams();
      int termvectorCounter = 0;
      for (String field : mtasFields.list.keySet()) {
        List<ComponentTermVector> tvList = mtasFields.list
            .get(field).termVectorList;
        if (tvList != null) {
          for (ComponentTermVector tv : tvList) {
            if (!tv.full) {
              if (missingTermvectorKeysShard.containsKey(tv.key)) {
                HashSet<String> list = missingTermvectorKeysShard.get(tv.key);
                if (!list.isEmpty()) {
                  paramsNewRequest.add(PARAM_MTAS_TERMVECTOR + "."
                      + termvectorCounter + "." + NAME_MTAS_TERMVECTOR_FIELD,
                      field);
                  paramsNewRequest.add(PARAM_MTAS_TERMVECTOR + "."
                      + termvectorCounter + "." + NAME_MTAS_TERMVECTOR_PREFIX,
                      tv.prefix);
                  paramsNewRequest.add(PARAM_MTAS_TERMVECTOR + "."
                      + termvectorCounter + "." + NAME_MTAS_TERMVECTOR_KEY,
                      tv.key);
                  if (tv.subComponentFunction.type != null) {
                    paramsNewRequest.add(
                        PARAM_MTAS_TERMVECTOR + "." + termvectorCounter + "."
                            + NAME_MTAS_TERMVECTOR_TYPE,
                        tv.subComponentFunction.type);
                  }
                  if (tv.distances != null) {
                    int distanceCounter = 0;
                    for (SubComponentDistance distance : tv.distances) {
                      paramsNewRequest.add(
                          PARAM_MTAS_TERMVECTOR + "." + termvectorCounter + "."
                              + NAME_MTAS_TERMVECTOR_DISTANCE + "."
                              + distanceCounter + "."
                              + NAME_MTAS_TERMVECTOR_DISTANCE_TYPE,
                          distance.type);
                      paramsNewRequest.add(
                          PARAM_MTAS_TERMVECTOR + "." + termvectorCounter + "."
                              + NAME_MTAS_TERMVECTOR_DISTANCE + "."
                              + distanceCounter + "."
                              + NAME_MTAS_TERMVECTOR_DISTANCE_BASE,
                          distance.base);
                      if (distance.key != null) {
                        paramsNewRequest.add(
                            PARAM_MTAS_TERMVECTOR + "." + termvectorCounter
                                + "." + NAME_MTAS_TERMVECTOR_DISTANCE + "."
                                + distanceCounter + "."
                                + NAME_MTAS_TERMVECTOR_DISTANCE_KEY,
                            distance.key);
                      }
                      if (distance.minimum != null) {
                        paramsNewRequest.add(
                            PARAM_MTAS_TERMVECTOR + "." + termvectorCounter
                                + "." + NAME_MTAS_TERMVECTOR_DISTANCE + "."
                                + distanceCounter + "."
                                + NAME_MTAS_TERMVECTOR_DISTANCE_MINIMUM,
                            String.valueOf(distance.minimum));
                      }
                      if (distance.maximum != null) {
                        paramsNewRequest.add(
                            PARAM_MTAS_TERMVECTOR + "." + termvectorCounter
                                + "." + NAME_MTAS_TERMVECTOR_DISTANCE + "."
                                + distanceCounter + "."
                                + NAME_MTAS_TERMVECTOR_DISTANCE_MAXIMUM,
                            String.valueOf(distance.maximum));
                      }
                      if (distance.parameters != null) {
                        for (Entry<String, String> parameter : distance.parameters
                            .entrySet()) {
                          paramsNewRequest.add(
                              PARAM_MTAS_TERMVECTOR + "." + termvectorCounter
                                  + "." + NAME_MTAS_TERMVECTOR_DISTANCE + "."
                                  + distanceCounter + "."
                                  + NAME_MTAS_TERMVECTOR_DISTANCE_PARAMETER
                                  + "." + parameter.getKey(),
                              parameter.getValue());
                        }
                      }
                      distanceCounter++;
                    }
                  }
                  if (tv.functions != null) {
                    int functionCounter = 0;
                    for (SubComponentFunction function : tv.functions) {
                      paramsNewRequest.add(
                          PARAM_MTAS_TERMVECTOR + "." + termvectorCounter + "."
                              + NAME_MTAS_TERMVECTOR_FUNCTION + "."
                              + functionCounter + "."
                              + NAME_MTAS_TERMVECTOR_FUNCTION_EXPRESSION,
                          function.expression);
                      paramsNewRequest.add(
                          PARAM_MTAS_TERMVECTOR + "." + termvectorCounter + "."
                              + NAME_MTAS_TERMVECTOR_FUNCTION + "."
                              + functionCounter + "."
                              + NAME_MTAS_TERMVECTOR_FUNCTION_KEY,
                          function.key);
                      if (function.type != null) {
                        paramsNewRequest.add(
                            PARAM_MTAS_TERMVECTOR + "." + termvectorCounter
                                + "." + NAME_MTAS_TERMVECTOR_FUNCTION + "."
                                + functionCounter + "."
                                + NAME_MTAS_TERMVECTOR_FUNCTION_TYPE,
                            function.type);
                      }
                      functionCounter++;
                    }
                  }
                  if (tv.regexp != null) {
                    paramsNewRequest.add(PARAM_MTAS_TERMVECTOR + "."
                        + termvectorCounter + "." + NAME_MTAS_TERMVECTOR_REGEXP,
                        tv.regexp);
                  }
                  if (!list.isEmpty()) {
                    StringBuilder listValue = new StringBuilder();
                    String[] listList = list.toArray(new String[list.size()]);
                    for (int i = 0; i < listList.length; i++) {
                      if (i > 0) {
                        listValue.append(",");
                      }
                      listValue.append(listList[i].replace("\\", "\\\\")
                          .replace(",", "\\\\"));
                    }
                    paramsNewRequest.add(PARAM_MTAS_TERMVECTOR + "."
                        + termvectorCounter + "." + NAME_MTAS_TERMVECTOR_FULL,
                        "false");
                    paramsNewRequest
                        .add(
                            PARAM_MTAS_TERMVECTOR + "." + termvectorCounter
                                + "." + NAME_MTAS_TERMVECTOR_LIST,
                            listValue.toString());
                  }
                  termvectorCounter++;
                }
              }
            }
          }
          if (termvectorCounter > 0) {
            ShardRequest nsreq = new ShardRequest();
            nsreq.shards = new String[] { entry.getKey() };
            nsreq.purpose = ShardRequest.PURPOSE_PRIVATE;
            nsreq.params = new ModifiableSolrParams();
            nsreq.params.add(CommonParams.FQ,
                rb.req.getParams().getParams(CommonParams.FQ));
            nsreq.params.add(CommonParams.Q,
                rb.req.getParams().getParams(CommonParams.Q));
            nsreq.params.add(CommonParams.CACHE,
                rb.req.getParams().getParams(CommonParams.CACHE));
            nsreq.params.add(CommonParams.ROWS, "0");
            nsreq.params.add(MtasSolrSearchComponent.PARAM_MTAS,
                rb.req.getOriginalParams()
                    .getParams(MtasSolrSearchComponent.PARAM_MTAS));
            nsreq.params.add(PARAM_MTAS_TERMVECTOR,
                rb.req.getOriginalParams().getParams(PARAM_MTAS_TERMVECTOR));
            nsreq.params.add(paramsNewRequest);
            rb.addRequest(searchComponent, nsreq);
          }
        }
      }
    }
  }
265869
private void prepareSpans(ResponseBuilder rb, ComponentFields mtasFields)
      throws IOException {
    SortedSet<String> ids = MtasSolrResultUtil
        .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_STATS_SPANS);
    if (!ids.isEmpty()) {
      int tmpCounter = 0;
      String[] fields = new String[ids.size()];
      String[] keys = new String[ids.size()];
      String[] minima = new String[ids.size()];
      String[] maxima = new String[ids.size()];
      String[] types = new String[ids.size()];
      String[][] functionExpressions = new String[ids.size()][];
      String[][] functionKeys = new String[ids.size()][];
      String[][] functionTypes = new String[ids.size()][];
      String[][] queryTypes = new String[ids.size()][];
      String[][] queryValues = new String[ids.size()][];
      String[][] queryIgnores = new String[ids.size()][];
      String[][] queryMaximumIgnoreLengths = new String[ids.size()][];
      String[][] queryPrefixes = new String[ids.size()][];
      HashMap<String, String[]>[][] queryVariables = new HashMap[ids.size()][];
      Boolean[] expand = new Boolean[ids.size()];
      for (String id : ids) {
        fields[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_SPANS + "."
            + id + "." + NAME_MTAS_STATS_SPANS_FIELD, null);
        keys[tmpCounter] = rb.req.getParams().get(
            PARAM_MTAS_STATS_SPANS + "." + id + "." + NAME_MTAS_STATS_SPANS_KEY,
            String.valueOf(tmpCounter)).trim();
        minima[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_SPANS + "."
            + id + "." + NAME_MTAS_STATS_SPANS_MINIMUM, null);
        maxima[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_SPANS + "."
            + id + "." + NAME_MTAS_STATS_SPANS_MAXIMUM, null);
        types[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_SPANS + "."
            + id + "." + NAME_MTAS_STATS_SPANS_TYPE, null);
        Set<String> functionIds = MtasSolrResultUtil
            .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_STATS_SPANS
                + "." + id + "." + NAME_MTAS_STATS_SPANS_FUNCTION);
        functionExpressions[tmpCounter] = new String[functionIds.size()];
        functionKeys[tmpCounter] = new String[functionIds.size()];
        functionTypes[tmpCounter] = new String[functionIds.size()];
        int tmpSubCounter = 0;
        for (String functionId : functionIds) {
          functionKeys[tmpCounter][tmpSubCounter] = rb.req.getParams()
              .get(
                  PARAM_MTAS_STATS_SPANS + "." + id + "."
                      + NAME_MTAS_STATS_SPANS_FUNCTION + "." + functionId + "."
                      + SUBNAME_MTAS_STATS_SPANS_FUNCTION_KEY,
                  String.valueOf(tmpSubCounter))
              .trim();
          functionExpressions[tmpCounter][tmpSubCounter] = rb.req.getParams()
              .get(PARAM_MTAS_STATS_SPANS + "." + id + "."
                  + NAME_MTAS_STATS_SPANS_FUNCTION + "." + functionId + "."
                  + SUBNAME_MTAS_STATS_SPANS_FUNCTION_EXPRESSION, null);
          functionTypes[tmpCounter][tmpSubCounter] = rb.req.getParams()
              .get(PARAM_MTAS_STATS_SPANS + "." + id + "."
                  + NAME_MTAS_STATS_SPANS_FUNCTION + "." + functionId + "."
                  + SUBNAME_MTAS_STATS_SPANS_FUNCTION_TYPE, null);
          tmpSubCounter++;
        }

        Set<String> qIds = MtasSolrResultUtil
            .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_STATS_SPANS
                + "." + id + "." + NAME_MTAS_STATS_SPANS_QUERY);
        if (!qIds.isEmpty()) {
          int tmpQCounter = 0;
          queryTypes[tmpCounter] = new String[qIds.size()];
          queryValues[tmpCounter] = new String[qIds.size()];
          queryIgnores[tmpCounter] = new String[qIds.size()];
          queryMaximumIgnoreLengths[tmpCounter] = new String[qIds.size()];
          queryPrefixes[tmpCounter] = new String[qIds.size()];
          queryVariables[tmpCounter] = new HashMap[qIds.size()];
          for (String qId : qIds) {
            queryTypes[tmpCounter][tmpQCounter] = rb.req.getParams()
                .get(PARAM_MTAS_STATS_SPANS + "." + id + "."
                    + NAME_MTAS_STATS_SPANS_QUERY + "." + qId + "."
                    + SUBNAME_MTAS_STATS_SPANS_QUERY_TYPE, null);
            queryValues[tmpCounter][tmpQCounter] = rb.req.getParams()
                .get(PARAM_MTAS_STATS_SPANS + "." + id + "."
                    + NAME_MTAS_STATS_SPANS_QUERY + "." + qId + "."
                    + SUBNAME_MTAS_STATS_SPANS_QUERY_VALUE, null);
            queryIgnores[tmpCounter][tmpQCounter] = rb.req.getParams()
                .get(PARAM_MTAS_STATS_SPANS + "." + id + "."
                    + NAME_MTAS_STATS_SPANS_QUERY + "." + qId + "."
                    + SUBNAME_MTAS_STATS_SPANS_QUERY_IGNORE, null);
            queryMaximumIgnoreLengths[tmpCounter][tmpQCounter] = rb.req
                .getParams().get(
                    PARAM_MTAS_STATS_SPANS + "." + id + "."
                        + NAME_MTAS_STATS_SPANS_QUERY + "." + qId + "."
                        + SUBNAME_MTAS_STATS_SPANS_QUERY_MAXIMUM_IGNORE_LENGTH,
                    null);
            queryPrefixes[tmpCounter][tmpQCounter] = rb.req.getParams()
                .get(PARAM_MTAS_STATS_SPANS + "." + id + "."
                    + NAME_MTAS_STATS_SPANS_QUERY + "." + qId + "."
                    + SUBNAME_MTAS_STATS_SPANS_QUERY_PREFIX, null);
            Set<String> vIds = MtasSolrResultUtil.getIdsFromParameters(
                rb.req.getParams(),
                PARAM_MTAS_STATS_SPANS + "." + id + "."
                    + NAME_MTAS_STATS_SPANS_QUERY + "." + qId + "."
                    + SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE);
            queryVariables[tmpCounter][tmpQCounter] = new HashMap<>();
            if (!vIds.isEmpty()) {
              HashMap<String, ArrayList<String>> tmpVariables = new HashMap<>();
              for (String vId : vIds) {
                String name = rb.req.getParams()
                    .get(PARAM_MTAS_STATS_SPANS + "." + id + "."
                        + NAME_MTAS_STATS_SPANS_QUERY + "." + qId + "."
                        + SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE + "." + vId
                        + "." + SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE_NAME,
                        null);
                if (name != null) {
                  if (!tmpVariables.containsKey(name)) {
                    tmpVariables.put(name, new ArrayList<String>());
                  }
                  String value = rb.req.getParams()
                      .get(PARAM_MTAS_STATS_SPANS + "." + id + "."
                          + NAME_MTAS_STATS_SPANS_QUERY + "." + qId + "."
                          + SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE + "." + vId
                          + "." + SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE_VALUE,
                          null);
                  if (value != null) {
                    ArrayList<String> list = new ArrayList<>();
                    String[] subList = value.split("(?<!\\\\),");
                    for (int i = 0; i < subList.length; i++) {
                      list.add(
                          subList[i].replace("\\,", ",").replace("\\\\", "\\"));
                    }
                    tmpVariables.get(name).addAll(list);
                  }
                }
              }
              for (Entry<String, ArrayList<String>> entry : tmpVariables
                  .entrySet()) {
                queryVariables[tmpCounter][tmpQCounter].put(entry.getKey(),
                    entry.getValue()
                        .toArray(new String[entry.getValue().size()]));
              }
            }
            tmpQCounter++;
          }
        } else {
          throw new IOException("no " + NAME_MTAS_STATS_SPANS_QUERY
              + " for mtas stats span " + id);
        }
        if (rb.req.getParams().getBool(PARAM_MTAS_STATS_SPANS + "." + id + "."
            + NAME_MTAS_STATS_SPANS_EXPAND, false)) {
          expand[tmpCounter] = true;
        } else {
          expand[tmpCounter] = false;
        }
        tmpCounter++;
      }
      String uniqueKeyField = rb.req.getSchema().getUniqueKeyField().getName();
      mtasFields.doStats = true;
      mtasFields.doStatsSpans = true;
      rb.setNeedDocSet(true);
      for (String field : fields) {
        if (field == null || field.isEmpty()) {
          throw new IOException("no (valid) field in mtas stats spans");
        } else if (!mtasFields.list.containsKey(field)) {
          mtasFields.list.put(field, new ComponentField(uniqueKeyField));
        }
      }
      MtasSolrResultUtil.compareAndCheck(keys, fields,
          NAME_MTAS_STATS_SPANS_KEY, NAME_MTAS_STATS_SPANS_FIELD, true);
      MtasSolrResultUtil.compareAndCheck(minima, fields,
          NAME_MTAS_STATS_SPANS_MINIMUM, NAME_MTAS_STATS_SPANS_FIELD, false);
      MtasSolrResultUtil.compareAndCheck(maxima, fields,
          NAME_MTAS_STATS_SPANS_MAXIMUM, NAME_MTAS_STATS_SPANS_FIELD, false);
      MtasSolrResultUtil.compareAndCheck(types, fields,
          NAME_MTAS_STATS_SPANS_TYPE, NAME_MTAS_STATS_SPANS_FIELD, false);
      MtasSolrResultUtil.compareAndCheck(types, fields,
          NAME_MTAS_STATS_SPANS_FUNCTION, NAME_MTAS_STATS_SPANS_FIELD, false);

      for (int i = 0; i < fields.length; i++) {
        ComponentField cf = mtasFields.list.get(fields[i]);
        int queryNumber = queryValues[i].length;
        MtasSpanQuery[] ql = new MtasSpanQuery[queryNumber];
        for (int j = 0; j < queryNumber; j++) {
          Integer maximumIgnoreLength = (queryMaximumIgnoreLengths[i][j] == null)
              ? null : Integer.parseInt(queryMaximumIgnoreLengths[i][j]);
          MtasSpanQuery q = MtasSolrResultUtil.constructQuery(queryValues[i][j],
              queryTypes[i][j], queryPrefixes[i][j], queryVariables[i][j],
              fields[i], queryIgnores[i][j], maximumIgnoreLength);
          // minimize number of queries
          if (cf.spanQueryList.contains(q)) {
            q = cf.spanQueryList.get(cf.spanQueryList.indexOf(q));
          } else {
            cf.spanQueryList.add(q);
          }
          ql[j] = q;
        }
        Double minimum = (minima[i] == null) || (minima[i].isEmpty()) ? null
            : Double.parseDouble(minima[i]);
        Double maximum = (maxima[i] == null) || (maxima[i].isEmpty()) ? null
            : Double.parseDouble(maxima[i]);
        String key = (keys[i] == null) || (keys[i].isEmpty())
            ? String.valueOf(i) + ":" + fields[i] + ":" + queryNumber
            : keys[i].trim();
        String type = (types[i] == null) || (types[i].isEmpty()) ? null
            : types[i].trim();
        String[] functionKey = functionKeys[i];
        String[] functionExpression = functionExpressions[i];
        String[] functionType = functionTypes[i];
        try {
          mtasFields.list.get(fields[i]).statsSpanList
              .add(new ComponentSpan(ql, key, minimum, maximum, type,
                  functionKey, functionExpression, functionType));
        } catch (ParseException e) {
          throw new IOException(e.getMessage());
        }
        if (expand[i]) {
          HashMap<String, String[]>[][] expandedQueryVariables = expandedQueryVariables(
              queryVariables[i]);
          for (int e = 0; e < expandedQueryVariables.length; e++) {
            MtasSpanQuery[] eql = new MtasSpanQuery[queryNumber];
            for (int j = 0; j < queryNumber; j++) {
              Integer maximumIgnoreLength = (queryMaximumIgnoreLengths[i][j] == null)
                  ? null : Integer.parseInt(queryMaximumIgnoreLengths[i][j]);
              MtasSpanQuery q = MtasSolrResultUtil.constructQuery(
                  queryValues[i][j], queryTypes[i][j], queryPrefixes[i][j],
                  expandedQueryVariables[e][j], fields[i], queryIgnores[i][j],
                  maximumIgnoreLength);
              // minimize number of queries
              if (cf.spanQueryList.contains(q)) {
                q = cf.spanQueryList.get(cf.spanQueryList.indexOf(q));
              } else {
                cf.spanQueryList.add(q);
              }
              eql[j] = q;
            }
            String newKey = generateKey(key + " (" + e + ")",
                expandedQueryVariables[e]);
            try {
              mtasFields.list.get(fields[i]).statsSpanList
                  .add(new ComponentSpan(eql, newKey, minimum, maximum, type,
                      functionKey, functionExpression, functionType));
            } catch (ParseException ee) {
              throw new IOException(ee.getMessage());
            }
          }
        }
      }
    } else {
      throw new IOException("missing parameters stats spans");
    }
  }
929797
public void readFields(ITuple tuple, Deserializer[] customDeserializers) throws IOException {
		readFields(tuple, readSchema, customDeserializers);
	}
1268064
@SuppressWarnings("unchecked")
  public void distributedProcess(ResponseBuilder rb, ComponentFields mtasFields)
      throws IOException {
    // rewrite
    NamedList<Object> mtasResponse = null;
    try {
      mtasResponse = (NamedList<Object>) rb.rsp.getValues().get("mtas");
    } catch (ClassCastException e) {
      log.debug(e);
      mtasResponse = null;
    }
    if (mtasResponse != null) {
      ArrayList<Object> mtasResponsePrefix;
      try {
        mtasResponsePrefix = (ArrayList<Object>) mtasResponse.get(NAME);
        if (mtasResponsePrefix != null) {
          NamedList<Object> mtasResponsePrefixItem;
          for (Object mtasResponsePrefixItemRaw : mtasResponsePrefix) {
            mtasResponsePrefixItem = (NamedList<Object>) mtasResponsePrefixItemRaw;
            repairPrefixItems(mtasResponsePrefixItem);
            MtasSolrResultUtil.rewrite(mtasResponsePrefixItem, searchComponent);
          }
        }
      } catch (ClassCastException e) {
        log.debug(e);
        mtasResponse.remove(NAME);
      }
    }
  }
174922
public FieldList move(int iRelPosition) throws DBException
    {
        this.setCurrentRecord(this.getBaseRecord());
        boolean bAfterRequery = !this.getBaseRecord().isOpen();
        if (!this.isOpen())
            this.open();    // Make sure any listeners are called before disabling.
        Object[] rgobjEnabledFields = this.getBaseRecord().setEnableNonFilter(null, false, false, false, false, true);
        try {
            Record record = (Record)super.move(iRelPosition);
            if (record == null)
                return null;

            this.getBaseRecord().setEnableNonFilter(rgobjEnabledFields, true, false, bAfterRequery, false, true);
            rgobjEnabledFields = null;
            
      //      this.getBaseRecord().handleValidRecord(); // Display Fields (handleValidRecord this was done in setEnableNonFilter)
            record = this.moveToCurrentRecord(record);
            if (record != null) if (record != this.getBaseRecord())
                record.handleValidRecord(); // Display Fields

            return record;
        } catch (DBException ex)    {
            throw ex;
        } finally {
            if (rgobjEnabledFields != null)
                this.getBaseRecord().setEnableNonFilter(rgobjEnabledFields, false, false, bAfterRequery, true, true);   // EOF
        }
    }
554903
private void init() throws IOException {
    // move to begin
    IndexInput inField = indexInputList.get("field");
    inField.seek(indexInputOffsetList.get("field"));
    // store field references in memory
    fieldReferences = new HashMap<String, FieldReferences>();
    boolean doInit = true;
    while (doInit) {
      try {
        String field = inField.readString();
        long refIndexDoc = inField.readVLong();
        long refIndexDocId = inField.readVLong();
        int numberOfDocs = inField.readVInt();
        inField.readVLong(); // refTerm
        inField.readVInt(); // numberOfTerms
        long refPrefix = inField.readVLong();
        int numberOfPrefixes = inField.readVInt();
        fieldReferences.put(field, new FieldReferences(refIndexDoc,
            refIndexDocId, numberOfDocs, refPrefix, numberOfPrefixes));
      } catch (IOException e) {
        log.debug(e);
        doInit = false;
      }
    }
    // prefixReferences
    prefixReferences = new HashMap<String, LinkedHashMap<String, Long>>();
  }
896997
public void finishStage(ResponseBuilder rb) {
    // System.out.println(
    // "collection: " + System.nanoTime() + " - " +
    // Thread.currentThread().getId()
    // + " - " + rb.req.getParams().getBool("isShard", false)
    // + " FINISHSTAGE " + rb.stage + " " + rb.req.getParamString());
    if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) {
      if (rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY
          && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) {
        ComponentFields mtasFields = getMtasFields(rb);
        if (mtasFields.doCollection) {
          if (rb.stage == ResponseBuilder.STAGE_EXECUTE_QUERY) {
            // mtas response
            NamedList<Object> mtasResponse = null;
            try {
              mtasResponse = (NamedList<Object>) rb.rsp.getValues()
                  .get(MtasSolrSearchComponent.NAME);
            } catch (ClassCastException e) {
              log.debug(e);
              mtasResponse = null;
            }
            if (mtasResponse == null) {
              mtasResponse = new SimpleOrderedMap<>();
              rb.rsp.add(MtasSolrSearchComponent.NAME, mtasResponse);
            }
            ArrayList<Object> mtasCollectionResponses;
            if (mtasResponse.get(NAME) != null
                && mtasResponse.get(NAME) instanceof ArrayList) {
              mtasCollectionResponses = (ArrayList<Object>) mtasResponse
                  .get(NAME);
            } else {
              mtasCollectionResponses = new ArrayList<>();
              mtasResponse.add(NAME, mtasCollectionResponses);
            }
            MtasSolrCollectionResult collectionResult;
            for (ComponentCollection componentCollection : mtasFields.collection) {
              try {
                collectionResult = createMtasSolrCollectionResult(
                    componentCollection, false);
                // Create response
                SimpleOrderedMap<Object> mtasCollectionResponse = new SimpleOrderedMap<>();
                mtasCollectionResponse.add("key", componentCollection.key);
                mtasCollectionResponse.add("data", collectionResult);
                mtasCollectionResponses.add(mtasCollectionResponse);
              } catch (IOException e) {
                log.debug(e);
              }
            }
          }
          // decode shard responses
          for (ShardRequest sreq : rb.finished) {
            if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
                && sreq.params.getBool(PARAM_MTAS_COLLECTION, false)) {
              for (ShardResponse shardResponse : sreq.responses) {
                NamedList<Object> solrShardResponse = shardResponse
                    .getSolrResponse().getResponse();
                try {
                  ArrayList<SimpleOrderedMap<Object>> data = (ArrayList<SimpleOrderedMap<Object>>) solrShardResponse
                      .findRecursive(MtasSolrSearchComponent.NAME, NAME);
                  if (data != null) {
                    MtasSolrResultUtil.decode(data);
                    if (rb.stage > ResponseBuilder.STAGE_EXECUTE_QUERY) {
                      ArrayList<SimpleOrderedMap<Object>> filteredData = new ArrayList<>();
                      for (SimpleOrderedMap<Object> dataItem : data) {
                        if (dataItem.get("data") != null && dataItem
                            .get("data") instanceof MtasSolrCollectionResult) {
                          MtasSolrCollectionResult collectionResult = (MtasSolrCollectionResult) dataItem
                              .get("data");
                          if (rb.stage <= MtasSolrSearchComponent.STAGE_COLLECTION_INIT) {
                            if (!collectionResult.action()
                                .equals(ComponentCollection.ACTION_CREATE)
                                && !collectionResult.action()
                                    .equals(ComponentCollection.ACTION_LIST)
                                && !collectionResult.action()
                                    .equals(ComponentCollection.ACTION_CHECK)) {
                              filteredData.add(dataItem);
                            }
                          } else if (rb.stage <= MtasSolrSearchComponent.STAGE_COLLECTION_FINISH) {
                            if (!collectionResult.action()
                                .equals(ComponentCollection.ACTION_POST)
                                && !collectionResult.action()
                                    .equals(ComponentCollection.ACTION_IMPORT)
                                && !collectionResult.action()
                                    .equals(ComponentCollection.ACTION_CHECK)) {
                              filteredData.add(dataItem);
                            }
                          }
                        } else {
                          filteredData.add(dataItem);
                        }
                      }
                      data.clear();
                      data.addAll(filteredData);
                    }
                  }
                } catch (ClassCastException e) {
                  log.debug(e);
                  // shouldn't happen
                }
              }
            }
          }
        }
      }
    }
  }
727496
private void computeFullStartPositionMinimum(int position)
      throws IOException {
    if (ignoreSpans != null && !minFullStartPosition.containsKey(position)) {
      HashSet<Integer> list = baseStartPositionList.get(position);
      HashSet<Integer> newList = new HashSet<>();
      int minimumStartPosition = position;
      while (list != null && !list.isEmpty()) {
        newList.clear();
        for (int startPosition : list) {
          if (minFullStartPosition.containsKey(startPosition)) {
            minimumStartPosition = Math.min(minimumStartPosition,
                minFullStartPosition.get(startPosition));
          } else if (baseStartPositionList.containsKey(startPosition)) {
            newList.addAll(baseStartPositionList.get(startPosition));
          } else {
            if (startPosition < minimumStartPosition) {
              minimumStartPosition = startPosition;
            }
          }
        }
        list.clear();
        list.addAll(newList);
      }
      minFullStartPosition.put(position, minimumStartPosition);
    }
  }