amit-jain commented on code in PR #2817:
URL: https://github.com/apache/jackrabbit-oak/pull/2817#discussion_r4535724805


##########
oak-search-lucene-ng/src/main/java/org/apache/jackrabbit/oak/plugins/index/luceneNg/LuceneNgIndexEditorProvider.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.index.luceneNg;
+
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.plugins.index.ContextAwareCallback;
+import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
+import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
+import org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback;
+import org.apache.jackrabbit.oak.plugins.index.IndexingContext;
+import 
org.apache.jackrabbit.oak.plugins.index.luceneNg.internal.editor.LuceneNgIndexEditorContext;
+import 
org.apache.jackrabbit.oak.plugins.index.luceneNg.directory.LuceneNgIndexCopier;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.spi.commit.Editor;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * IndexEditorProvider for Lucene 9 indexes.
+ * Routes index write operations to Lucene 9 editor for luceneNg type indexes.
+ */
+public class LuceneNgIndexEditorProvider implements IndexEditorProvider {
+    private static final Logger LOG = 
LoggerFactory.getLogger(LuceneNgIndexEditorProvider.class);
+
+    private final LuceneNgIndexTracker indexTracker;
+    @Nullable
+    private final LuceneNgIndexCopier copier;
+
+    /**
+     * Creates a new LuceneNgIndexEditorProvider.
+     *
+     * @param indexTracker the index tracker for managing index lifecycle
+     */
+    public LuceneNgIndexEditorProvider(@NotNull LuceneNgIndexTracker 
indexTracker) {
+        this(indexTracker, null);
+    }
+
+    public LuceneNgIndexEditorProvider(@NotNull LuceneNgIndexTracker 
indexTracker,
+                                      @Nullable LuceneNgIndexCopier copier) {
+        this.indexTracker = indexTracker;
+        this.copier = copier;
+    }
+
+    @Override
+    @Nullable
+    public Editor getIndexEditor(@NotNull String type,
+                                 @NotNull NodeBuilder definition,
+                                 @NotNull NodeState root,
+                                 @NotNull IndexUpdateCallback callback)
+            throws CommitFailedException {
+
+        // Only handle luceneNg type indexes
+        if (!LuceneNgIndexConstants.TYPE_LUCENE_NG.equals(type)) {
+            return null;
+        }
+
+        LOG.debug("Creating Lucene 9 index editor for type: {}", type);
+
+        if (!(callback instanceof ContextAwareCallback)) {
+            throw new IllegalStateException("callback instance not of type 
ContextAwareCallback [" + callback + "]");
+        }
+        IndexingContext indexingContext = ((ContextAwareCallback) 
callback).getIndexingContext();
+
+        // Nested luceneNg definitions (below /oak:index) are not queryable by 
LuceneNgIndex, so
+        // skip indexing them rather than maintaining an index that can never 
be queried.
+        String indexPath = indexingContext.getIndexPath();
+        if (indexPath == null || 
!"/oak:index".equals(PathUtils.getParentPath(indexPath))) {
+            LOG.warn("luceneNg index at {} is not supported below /oak:index; 
skipping", indexPath);
+            return null;
+        }
+
+        // Near-real-time and synchronous indexing are not supported: an index 
with an async lane
+        // is written only by the async indexer, never during user commits.
+        if (!indexingContext.isAsync() && 
definition.hasProperty(IndexConstants.ASYNC_PROPERTY_NAME)) {
+            return null;
+        }

Review Comment:
   **`sync` definitions lose commit-time visibility and `unique` enforcement**
   
   Skipping the commit pass is fine for `nrt`. For `sync`, legacy also persists 
sync property entries during the commit and enforces `unique` there 
([`LuceneIndexEditorProvider` 
L218-224](https://github.com/bhabegger/jackrabbit-oak/blob/1c6ae44f2de29e7e855c18b1bd0c2af38a1a193d/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorProvider.java#L218-L224)).
 With `async = ["async", "sync"]`, luceneNg doesn't show a change until the 
async lane runs, and it accepts duplicates on `unique` properties without an 
error. A lane-less `async = "sync"` definition is never indexed.
   
   The README (L161-164) doesn't mention the `unique` part. Please either 
support sync property definitions as legacy does, or document `sync`/`unique` 
as unsupported and reject or WARN on such definitions.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to