private void updateDocOrDocValues()

in encryption/src/main/java/org/apache/solr/update/DirectUpdateHandler2Copy.java [1029:1071]


  private void updateDocOrDocValues(AddUpdateCommand cmd, IndexWriter writer) throws IOException {
    // this code path requires an idField in order to potentially replace a doc
    assert idField != null;
    boolean hasUpdateTerm = cmd.updateTerm != null; // AKA dedupe

    if (cmd.isInPlaceUpdate()) {
      if (hasUpdateTerm) {
        throw new IllegalStateException(
          "cmd.updateTerm/dedupe is not compatible with in-place updates");
      }
      // we don't support the solrInputDoc with nested child docs either but we'll throw an
      // exception if attempted

      // can't use cmd.getIndexedId because it will be a root doc if this doc is a child
      Term updateTerm =
        new Term(
          idField.getName(),
          core.getLatestSchema().indexableUniqueKey(cmd.getSelfOrNestedDocIdStr()));
      // skips uniqueKey and _root_
      List<IndexableField> fields = cmd.makeLuceneDocForInPlaceUpdate().getFields();
      log.debug("updateDocValues({})", cmd);
      writer.updateDocValues(updateTerm, fields.toArray(new Field[fields.size()]));

    } else { // more normal path

      Iterable<Document> nestedDocs = cmd.makeLuceneDocs();
      Term idTerm = getIdTerm(cmd.getIndexedId());
      Term updateTerm = hasUpdateTerm ? cmd.updateTerm : idTerm;

      log.debug("updateDocuments({})", cmd);
      writer.updateDocuments(updateTerm, nestedDocs);

      // If hasUpdateTerm, then delete any existing documents with the same ID other than the one
      // added above (used in near-duplicate replacement)
      if (hasUpdateTerm) { // rare
        BooleanQuery.Builder bq = new BooleanQuery.Builder();
        // don't want the one we added above (will be unique)
        bq.add(new TermQuery(updateTerm), Occur.MUST_NOT);
        bq.add(new TermQuery(idTerm), Occur.MUST); // same ID
        writer.deleteDocuments(new DeleteByQueryWrapper(bq.build(), core.getLatestSchema()));
      }
    }
  }