public synchronized void merge()

in indexer-core/src/main/java/org/apache/maven/index/context/DefaultIndexingContext.java [594:660]


    public synchronized void merge(
            Directory directory, DocumentFilter filter, Set<String> allGroups, Set<String> rootGroups)
            throws IOException {
        final IndexSearcher s = acquireIndexSearcher();
        try {
            final IndexWriter w = getIndexWriter();
            try (IndexReader directoryReader = DirectoryReader.open(directory)) {
                int numDocs = directoryReader.maxDoc();

                Bits liveDocs = MultiBits.getLiveDocs(directoryReader);
                StoredFields storedFields = directoryReader.storedFields();
                for (int i = 0; i < numDocs; i++) {
                    if (liveDocs != null && !liveDocs.get(i)) {
                        continue;
                    }

                    Document d = storedFields.document(i);
                    if (filter != null && !filter.accept(d)) {
                        continue;
                    }

                    String uinfo = d.get(ArtifactInfo.UINFO);
                    if (uinfo != null) {
                        TopScoreDocCollector collector = TopScoreDocCollector.create(1, 1);
                        s.search(new TermQuery(new Term(ArtifactInfo.UINFO, uinfo)), collector);
                        if (collector.getTotalHits() == 0) {
                            w.addDocument(IndexUtils.updateDocument(d, this, false));
                        }
                    } else {
                        String deleted = d.get(ArtifactInfo.DELETED);

                        if (deleted != null) {
                            // Deleting the document loses history that it was delete,
                            // so incrementals wont work. Therefore, put the delete
                            // document in as well
                            w.deleteDocuments(new Term(ArtifactInfo.UINFO, deleted));
                            w.addDocument(d);
                        }
                    }
                }

            } finally {
                commit();
            }
            if (allGroups == null && rootGroups == null) {
                rebuildGroups();
            } else {
                if (rootGroups != null) {
                    this.rootGroups.get().addAll(rootGroups);
                }
                if (allGroups != null) {
                    this.allGroups.get().addAll(allGroups);
                }
            }
            Date mergedTimestamp = IndexUtils.getTimestamp(directory);

            if (getTimestamp() != null && mergedTimestamp != null && mergedTimestamp.after(getTimestamp())) {
                // we have both, keep the newest
                updateTimestamp(true, mergedTimestamp);
            } else {
                updateTimestamp(true);
            }
            optimize();
        } finally {
            releaseIndexSearcher(s);
        }
    }