bhabegger commented on code in PR #2817: URL: https://github.com/apache/jackrabbit-oak/pull/2817#discussion_r4535876248
########## 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: I would propose we document this for now. @thomasmueller Any opinions here ? How far should we go with parity between luceneNg and lucene ? -- 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]
