docs: private static void createDocument(List<ComponentDocument> documentList,
        List<Integer> docList, String uniqueKeyField, IndexSearcher searcher,
        Terms t, LeafReaderContext lrc) throws IOException {
      if (documentList != null) {
        SortedSet<String> listStatsItems = CodecUtil.createStatsItems("sum");
        String listStatsType = CodecUtil.createStatsType(listStatsItems,
            CodecUtil.STATS_TYPE_SUM, null);
        for (ComponentDocument document : documentList) {
          // initialize
          for (int docId : docList) {
            // get unique id
            Document doc = searcher.doc(docId,
                new HashSet<String>(Arrays.asList(uniqueKeyField)));
            IndexableField indxfld = doc.getField(uniqueKeyField);
            // get other doc info
            if (indxfld != null) {
              document.uniqueKey.put(docId, indxfld.stringValue());
              MtasDataCollector<?, ?> stats = DataCollector.getCollector(
                  DataCollector.COLLECTOR_TYPE_DATA, document.dataType,
                  document.statsType, document.statsItems, null, null, null, null,
                  null, null);
              document.statsData.put(docId, stats);
              if (document.statsList != null) {
                MtasDataCollector<?, ?> list;
                if (document.listExpand) {
                  SortedSet<String>[] baseStatsItems = new SortedSet[] {
                      listStatsItems };
                  list = DataCollector.getCollector(
                      DataCollector.COLLECTOR_TYPE_LIST, CodecUtil.DATA_TYPE_LONG,
                      listStatsType, listStatsItems, CodecUtil.STATS_TYPE_SUM,
                      CodecUtil.SORT_DESC, 0, document.listNumber,
                      new String[] { DataCollector.COLLECTOR_TYPE_LIST },
                      new String[] { CodecUtil.DATA_TYPE_LONG },
                      new String[] { listStatsType },
                      Arrays.copyOfRange(baseStatsItems, 0,
                          baseStatsItems.length),
                      new String[] { CodecUtil.STATS_TYPE_SUM },
                      new String[] { CodecUtil.SORT_DESC }, new Integer[] { 0 },
                      new Integer[] { document.listExpandNumber }, null, null);
                } else {
                  list = DataCollector.getCollector(
                      DataCollector.COLLECTOR_TYPE_LIST, CodecUtil.DATA_TYPE_LONG,
                      listStatsType, listStatsItems, CodecUtil.STATS_TYPE_SUM,
                      CodecUtil.SORT_DESC, 0, document.listNumber, null, null);
                }
                document.statsList.put(docId, list);
              }
            }
          }
        }
        // collect
        if (t != null) {
          BytesRef term;
          TermsEnum termsEnum;
          PostingsEnum postingsEnum = null;
          // loop over termvectors
          for (ComponentDocument document : documentList) {
  
            List<CompiledAutomaton> listAutomata;
            Map<String, Automaton> automatonMap;
            Map<String, ByteRunAutomaton> byteRunAutomatonMap;
            if (document.list == null) {
              automatonMap = null;
              byteRunAutomatonMap = null;
              listAutomata = new ArrayList<>();
              CompiledAutomaton compiledAutomaton;
              Automaton automaton;
              if ((document.regexp == null) || (document.regexp.isEmpty())) {
                RegExp re = new RegExp(
                    document.prefix + MtasToken.DELIMITER + ".*");
                automaton = re.toAutomaton();
              } else {
                RegExp re = new RegExp(document.prefix + MtasToken.DELIMITER
                    + document.regexp + "\u0000*");
                automaton = re.toAutomaton();
              }
              compiledAutomaton = new CompiledAutomaton(automaton);
              listAutomata.add(compiledAutomaton);
            } else {
              automatonMap = MtasToken.createAutomatonMap(document.prefix,
                  new ArrayList<String>(document.list),
                  document.listRegexp ? false : true);
              byteRunAutomatonMap = MtasToken.byteRunAutomatonMap(automatonMap);
              listAutomata = MtasToken.createAutomata(document.prefix,
                  document.regexp, automatonMap);
            }
            List<ByteRunAutomaton> ignoreByteRunAutomatonList = null;
            if ((document.ignoreRegexp != null)
                && (!document.ignoreRegexp.isEmpty())) {
              ignoreByteRunAutomatonList = new ArrayList<>();
              RegExp re = new RegExp(document.prefix + MtasToken.DELIMITER
                  + document.ignoreRegexp + "\u0000*");
              ignoreByteRunAutomatonList
                  .add(new ByteRunAutomaton(re.toAutomaton()));
            }
            if (document.ignoreList != null) {
              if (ignoreByteRunAutomatonList == null) {
                ignoreByteRunAutomatonList = new ArrayList<>();
              }
              Map<String, Automaton> list = MtasToken.createAutomatonMap(
                  document.prefix, new ArrayList<String>(document.ignoreList),
                  document.ignoreListRegexp ? false : true);
              for (Automaton automaton : list.values()) {
                ignoreByteRunAutomatonList.add(new ByteRunAutomaton(automaton));
              }
            }
  
            for (CompiledAutomaton compiledAutomaton : listAutomata) {
              if (!compiledAutomaton.type
                  .equals(CompiledAutomaton.AUTOMATON_TYPE.NONE)) {
                termsEnum = t.intersect(compiledAutomaton, null);
                // init
                int initBaseSize = Math.min((int) t.size(), 1000);
                int initListSize = document.statsList != null
                    ? Math.min(document.statsList.size(), initBaseSize)
                    : initBaseSize;
                HashSet<MtasDataCollector<?, ?>> initialised = new HashSet<>();
                for (int docId : docList) {
                  document.statsData.get(docId).initNewList(1);
                  initialised.add(document.statsData.get(docId));
                  if (document.statsList != null
                      && document.statsList.size() > 0) {
                    document.statsList.get(docId).initNewList(initListSize);
                    initialised.add(document.statsList.get(docId));
                  }
                }
                // fill
                int termDocId;
                boolean acceptedTerm;
                while ((term = termsEnum.next()) != null) {
                  Iterator<Integer> docIterator = docList.iterator();
                  postingsEnum = termsEnum.postings(postingsEnum,
                      PostingsEnum.FREQS);
                  termDocId = -1;
                  acceptedTerm = true;
                  if (ignoreByteRunAutomatonList != null) {
                    for (ByteRunAutomaton ignoreByteRunAutomaton : ignoreByteRunAutomatonList) {
                      if (ignoreByteRunAutomaton.run(term.bytes, term.offset,
                          term.length)) {
                        acceptedTerm = false;
                        break;
                      }
                    }
                  }
                  if (acceptedTerm) {
                    while (docIterator.hasNext()) {
                      int segmentDocId = docIterator.next() - lrc.docBase;
                      if (segmentDocId >= termDocId
                          && ((segmentDocId == termDocId)
                              || ((termDocId = postingsEnum
                                  .advance(segmentDocId)) == segmentDocId))) {
                        // register stats
                        document.statsData.get(segmentDocId + lrc.docBase)
                            .add(new long[] { postingsEnum.freq() }, 1);
                        // register list
                        if (document.statsList != null) {
                          if (automatonMap != null) {
                            MtasDataCollector<?, ?> dataCollector;
                            MtasDataCollector<?, ?> subSataCollector;
                            for (Entry<String, ByteRunAutomaton> entry : byteRunAutomatonMap
                                .entrySet()) {
                              ByteRunAutomaton bra = entry.getValue();
                              if (bra.run(term.bytes, term.offset, term.length)) {
                                dataCollector = document.statsList
                                    .get(segmentDocId + lrc.docBase);
                                subSataCollector = dataCollector.add(
                                    entry.getKey(),
                                    new long[] { postingsEnum.freq() }, 1);
                                if (document.listExpand
                                    && subSataCollector != null) {
                                  if (!initialised.contains(subSataCollector)) {
                                    subSataCollector.initNewList(initBaseSize);
                                    initialised.add(subSataCollector);
                                  }
                                  subSataCollector.add(
                                      MtasToken.getPostfixFromValue(term),
                                      new long[] { postingsEnum.freq() }, 1);
                                }
                              }
                            }
                          } else {
                            document.statsList.get(segmentDocId + lrc.docBase)
                                .add(MtasToken.getPostfixFromValue(term),
                                    new long[] { postingsEnum.freq() }, 1);
                          }
                        }
                      }
                    }
                  }
                }
                // close
                for (MtasDataCollector<?, ?> item : initialised) {
                  item.closeNewList();
                }
                initialised.clear();
              }
            }
          }
        }
      }
    }