Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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.lucene;

import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.oak.InitialContent;
import org.apache.jackrabbit.oak.Oak;
import org.apache.jackrabbit.oak.api.ContentRepository;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants;
import org.apache.jackrabbit.oak.plugins.index.search.test.AbstractIndexComparisonTest;
import org.apache.jackrabbit.oak.spi.commit.Observer;
import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;

import java.util.List;

import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NODE_TYPE;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_PROPERTY_NAME;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME;
import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.INCLUDE_PROPERTY_NAMES;
import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;

/**
* Runs the shared {@link AbstractIndexComparisonTest} scenarios against the legacy Lucene backend.
*/
public class LuceneIndexComparisonTest extends AbstractIndexComparisonTest {

@Override
protected ContentRepository createRepository() {
LuceneIndexProvider provider = new LuceneIndexProvider();
return new Oak()
.with(new InitialContent())
.with(new OpenSecurityProvider())
.with((QueryIndexProvider) provider)
.with((Observer) provider)
.with(new LuceneIndexEditorProvider())
.createContentRepository();
}

@Override
protected void createTestIndexNode() throws Exception {
setTraversalEnabled(false);
}

@Override
protected void createSearchIndex() throws Exception {
Tree def = root.getTree("/oak:index").addChild("luceneTestIndex");
def.setProperty(JcrConstants.JCR_PRIMARYTYPE, INDEX_DEFINITIONS_NODE_TYPE, Type.NAME);
def.setProperty(TYPE_PROPERTY_NAME, LuceneIndexConstants.TYPE_LUCENE);
def.setProperty(REINDEX_PROPERTY_NAME, true);
def.setProperty(FulltextIndexConstants.FULL_TEXT_ENABLED, false);
def.setProperty(createProperty(INCLUDE_PROPERTY_NAMES,
List.of("title", "description", "age", "price", "status", "category"), Type.STRINGS));
// This is the old-style flat index definition format (fulltextEnabled=false +
// includePropertyNames): IndexDefinition#createIndexRules defaults every included
// property to propertyIndex=true, analyzed=false when fulltextEnabled is false. To keep
// that default (and every other scenario indexed the same way as before) while still
// supporting CONTAINS(description, ...), add an explicit per-property override under the
// old-format "properties" node -- IndexDefinition#createIndexRules copies any properties
// found there over the computed defaults for that single property (see
// getPropDefnNode/"Copy over the property configuration" in IndexDefinition.java), so
// only "description" gains analyzed=true; every other property (and description's own
// propertyIndex=true, needed by testDescriptionQuery) is unaffected.
Tree props = def.addChild(FulltextIndexConstants.PROP_NODE);
Tree descriptionProp = props.addChild("description");
descriptionProp.setProperty(FulltextIndexConstants.PROP_ANALYZED, true);
root.commit();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.apache.jackrabbit.oak.plugins.index.lucene;

import org.apache.jackrabbit.oak.InitialContent;
import org.apache.jackrabbit.oak.Oak;
import org.apache.jackrabbit.oak.api.ContentRepository;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants;
import org.apache.jackrabbit.oak.query.AbstractQueryTest;
import org.apache.jackrabbit.oak.spi.commit.Observer;
import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
import org.junit.Test;

import java.util.List;

import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.*;
import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.INCLUDE_PROPERTY_NAMES;
import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;

public class LuceneIndexMinimalTest extends AbstractQueryTest {
@Override protected void createTestIndexNode() throws Exception { setTraversalEnabled(false); }

@Override
protected ContentRepository createRepository() {
LuceneIndexProvider provider = new LuceneIndexProvider();
return new Oak().with(new InitialContent()).with(new OpenSecurityProvider())
.with((QueryIndexProvider) provider).with((Observer) provider)
.with(new LuceneIndexEditorProvider()).createContentRepository();
}

@Test
public void singleCommit() throws Exception {
// Index + content in ONE commit
Tree def = root.getTree("/oak:index").addChild("testIdx");
def.setProperty("jcr:primaryType", INDEX_DEFINITIONS_NODE_TYPE, Type.NAME);
def.setProperty(TYPE_PROPERTY_NAME, LuceneIndexConstants.TYPE_LUCENE);
def.setProperty(REINDEX_PROPERTY_NAME, true);
def.setProperty(FulltextIndexConstants.FULL_TEXT_ENABLED, false);
def.setProperty(createProperty(INCLUDE_PROPERTY_NAMES, List.of("title"), Type.STRINGS));

Tree page = root.getTree("/").addChild("content").addChild("page1");
page.setProperty("title", "Lucene Integration");
root.commit();

assertQuery("//element(*, nt:base)[@title = 'Lucene Integration']", "xpath", List.of("/content/page1"));
}

@Test
public void twoCommits() throws Exception {
// Index in first commit, content in second
Tree def = root.getTree("/oak:index").addChild("testIdx");
def.setProperty("jcr:primaryType", INDEX_DEFINITIONS_NODE_TYPE, Type.NAME);
def.setProperty(TYPE_PROPERTY_NAME, LuceneIndexConstants.TYPE_LUCENE);
def.setProperty(REINDEX_PROPERTY_NAME, true);
def.setProperty(FulltextIndexConstants.FULL_TEXT_ENABLED, false);
def.setProperty(createProperty(INCLUDE_PROPERTY_NAMES, List.of("title"), Type.STRINGS));
root.commit();

Tree page = root.getTree("/").addChild("content").addChild("page1");
page.setProperty("title", "Lucene Integration");
root.commit();

assertQuery("//element(*, nt:base)[@title = 'Lucene Integration']", "xpath", List.of("/content/page1"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.lucene;

import org.apache.jackrabbit.oak.Oak;
import org.apache.jackrabbit.oak.jcr.Jcr;
import org.apache.jackrabbit.oak.plugins.index.LuceneIndexOptions;
import org.apache.jackrabbit.oak.plugins.index.NodeNameCommonTest;
import org.junit.After;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;

import javax.jcr.Repository;
import java.io.File;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
* Runs {@link NodeNameCommonTest} against the legacy Lucene index.
*/
public class LuceneNodeNameCommonTest extends NodeNameCommonTest {

private ExecutorService executorService = Executors.newFixedThreadPool(2);

@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder(new File("target"));

@Override
protected Repository createJcrRepository() {
indexOptions = new LuceneIndexOptions();
repositoryOptionsUtil = new LuceneTestRepositoryBuilder(executorService, temporaryFolder).build();
Oak oak = repositoryOptionsUtil.getOak();
return new Jcr(oak).createRepository();
}

@After
public void shutdownExecutor() {
executorService.shutdown();
}
}
Loading