Skip to content

Commit dbccf97

Browse files
committed
feat: add lucene9 index provider as safe opt-in target
Introduce the oak-search-luceneNg module with lucene9 query/editor wiring, parity fixes, and indexing regressions covered while keeping behavior unchanged unless index definitions explicitly use type=lucene9. Made-with: Cursor
1 parent bdac730 commit dbccf97

48 files changed

Lines changed: 8239 additions & 1 deletion

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/ContextAwareCallback.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,25 @@
1919

2020
package org.apache.jackrabbit.oak.plugins.index;
2121

22+
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
23+
2224
/**
2325
* Extension to IndexUpdateCallback which also provides access to
24-
* {@link IndexingContext}
26+
* {@link IndexingContext} and the root {@link NodeBuilder} for the current commit.
2527
*/
2628
public interface ContextAwareCallback extends IndexUpdateCallback {
2729

2830
IndexingContext getIndexingContext();
31+
32+
/**
33+
* Returns the root {@link NodeBuilder} for the current commit, allowing
34+
* index editors to write data outside the index definition subtree
35+
* (e.g. to {@code /var/indexing/lucene/<indexName>}).
36+
*
37+
* @return the root NodeBuilder, or {@code null} when not available
38+
* (e.g. in test contexts where a plain mock is used)
39+
*/
40+
default NodeBuilder getRootBuilder() {
41+
return null;
42+
}
2943
}

oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ private static final class IndexUpdateRootState {
637637
final IndexEditorProvider provider;
638638
final String async;
639639
final NodeState root;
640+
final NodeBuilder rootBuilder;
640641
final CommitInfo commitInfo;
641642
final IndexDisabler indexDisabler;
642643
private boolean ignoreReindexFlags = IGNORE_REINDEX_FLAGS;
@@ -654,6 +655,7 @@ private IndexUpdateRootState(IndexEditorProvider provider, String async, NodeSta
654655
this.provider = requireNonNull(provider);
655656
this.async = async;
656657
this.root = requireNonNull(root);
658+
this.rootBuilder = requireNonNull(builder);
657659
this.commitInfo = commitInfo;
658660
this.corruptIndexHandler = corruptIndexHandler;
659661
this.indexDisabler = new IndexDisabler(builder);
@@ -726,6 +728,11 @@ public IndexingContext getIndexingContext() {
726728
return this;
727729
}
728730

731+
@Override
732+
public NodeBuilder getRootBuilder() {
733+
return IndexUpdateRootState.this.rootBuilder;
734+
}
735+
729736
//~--------------------------------< IndexingContext >
730737

731738
@Override

oak-lucene/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,12 @@
369369
<type>test-jar</type>
370370
<scope>test</scope>
371371
</dependency>
372+
<dependency>
373+
<groupId>org.apache.jackrabbit</groupId>
374+
<artifactId>oak-search-test</artifactId>
375+
<version>${project.version}</version>
376+
<scope>test</scope>
377+
</dependency>
372378
<dependency>
373379
<groupId>org.apache.jackrabbit</groupId>
374380
<artifactId>jackrabbit-core</artifactId>

oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ private void registerIndexEditor(BundleContext bundleContext, IndexTracker track
514514

515515
Dictionary<String, Object> props = new Hashtable<>();
516516
props.put("type", TYPE_LUCENE);
517+
props.put("leaf", Boolean.TRUE);
517518
regs.add(bundleContext.registerService(IndexEditorProvider.class.getName(), editorProvider, props));
518519
oakRegs.add(registerMBean(whiteboard,
519520
TextExtractionStatsMBean.class,
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.jackrabbit.oak.plugins.index.lucene;
18+
19+
import org.apache.jackrabbit.JcrConstants;
20+
import org.apache.jackrabbit.oak.InitialContent;
21+
import org.apache.jackrabbit.oak.Oak;
22+
import org.apache.jackrabbit.oak.api.ContentRepository;
23+
import org.apache.jackrabbit.oak.api.Tree;
24+
import org.apache.jackrabbit.oak.api.Type;
25+
import org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants;
26+
import org.apache.jackrabbit.oak.plugins.index.search.test.AbstractIndexComparisonTest;
27+
import org.apache.jackrabbit.oak.spi.commit.Observer;
28+
import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
29+
import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
30+
31+
import java.util.List;
32+
33+
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NODE_TYPE;
34+
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_PROPERTY_NAME;
35+
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME;
36+
import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.INCLUDE_PROPERTY_NAMES;
37+
import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
38+
39+
/**
40+
* Runs the shared {@link AbstractIndexComparisonTest} scenarios against the legacy Lucene backend.
41+
*/
42+
public class LuceneIndexComparisonTest extends AbstractIndexComparisonTest {
43+
44+
@Override
45+
protected ContentRepository createRepository() {
46+
LuceneIndexProvider provider = new LuceneIndexProvider();
47+
return new Oak()
48+
.with(new InitialContent())
49+
.with(new OpenSecurityProvider())
50+
.with((QueryIndexProvider) provider)
51+
.with((Observer) provider)
52+
.with(new LuceneIndexEditorProvider())
53+
.createContentRepository();
54+
}
55+
56+
@Override
57+
protected void createTestIndexNode() throws Exception {
58+
setTraversalEnabled(false);
59+
}
60+
61+
@Override
62+
protected void createSearchIndex() throws Exception {
63+
Tree def = root.getTree("/oak:index").addChild("luceneTestIndex");
64+
def.setProperty(JcrConstants.JCR_PRIMARYTYPE, INDEX_DEFINITIONS_NODE_TYPE, Type.NAME);
65+
def.setProperty(TYPE_PROPERTY_NAME, LuceneIndexConstants.TYPE_LUCENE);
66+
def.setProperty(REINDEX_PROPERTY_NAME, true);
67+
def.setProperty(FulltextIndexConstants.FULL_TEXT_ENABLED, false);
68+
def.setProperty(createProperty(INCLUDE_PROPERTY_NAMES,
69+
List.of("title", "description", "age", "price", "status", "category"), Type.STRINGS));
70+
root.commit();
71+
}
72+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package org.apache.jackrabbit.oak.plugins.index.lucene;
2+
3+
import org.apache.jackrabbit.oak.InitialContent;
4+
import org.apache.jackrabbit.oak.Oak;
5+
import org.apache.jackrabbit.oak.api.ContentRepository;
6+
import org.apache.jackrabbit.oak.api.Tree;
7+
import org.apache.jackrabbit.oak.api.Type;
8+
import org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants;
9+
import org.apache.jackrabbit.oak.query.AbstractQueryTest;
10+
import org.apache.jackrabbit.oak.spi.commit.Observer;
11+
import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
12+
import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
13+
import org.junit.Test;
14+
15+
import java.util.List;
16+
17+
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.*;
18+
import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.INCLUDE_PROPERTY_NAMES;
19+
import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
20+
21+
public class LuceneIndexMinimalTest extends AbstractQueryTest {
22+
@Override protected void createTestIndexNode() throws Exception { setTraversalEnabled(false); }
23+
24+
@Override
25+
protected ContentRepository createRepository() {
26+
LuceneIndexProvider provider = new LuceneIndexProvider();
27+
return new Oak().with(new InitialContent()).with(new OpenSecurityProvider())
28+
.with((QueryIndexProvider) provider).with((Observer) provider)
29+
.with(new LuceneIndexEditorProvider()).createContentRepository();
30+
}
31+
32+
@Test
33+
public void singleCommit() throws Exception {
34+
// Index + content in ONE commit
35+
Tree def = root.getTree("/oak:index").addChild("testIdx");
36+
def.setProperty("jcr:primaryType", INDEX_DEFINITIONS_NODE_TYPE, Type.NAME);
37+
def.setProperty(TYPE_PROPERTY_NAME, LuceneIndexConstants.TYPE_LUCENE);
38+
def.setProperty(REINDEX_PROPERTY_NAME, true);
39+
def.setProperty(FulltextIndexConstants.FULL_TEXT_ENABLED, false);
40+
def.setProperty(createProperty(INCLUDE_PROPERTY_NAMES, List.of("title"), Type.STRINGS));
41+
42+
Tree page = root.getTree("/").addChild("content").addChild("page1");
43+
page.setProperty("title", "Lucene Integration");
44+
root.commit();
45+
46+
assertQuery("//element(*, nt:base)[@title = 'Lucene Integration']", "xpath", List.of("/content/page1"));
47+
}
48+
49+
@Test
50+
public void twoCommits() throws Exception {
51+
// Index in first commit, content in second
52+
Tree def = root.getTree("/oak:index").addChild("testIdx");
53+
def.setProperty("jcr:primaryType", INDEX_DEFINITIONS_NODE_TYPE, Type.NAME);
54+
def.setProperty(TYPE_PROPERTY_NAME, LuceneIndexConstants.TYPE_LUCENE);
55+
def.setProperty(REINDEX_PROPERTY_NAME, true);
56+
def.setProperty(FulltextIndexConstants.FULL_TEXT_ENABLED, false);
57+
def.setProperty(createProperty(INCLUDE_PROPERTY_NAMES, List.of("title"), Type.STRINGS));
58+
root.commit();
59+
60+
Tree page = root.getTree("/").addChild("content").addChild("page1");
61+
page.setProperty("title", "Lucene Integration");
62+
root.commit();
63+
64+
assertQuery("//element(*, nt:base)[@title = 'Lucene Integration']", "xpath", List.of("/content/page1"));
65+
}
66+
}

0 commit comments

Comments
 (0)