Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexStatisticsTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexStatisticsTest.java?rev=1841926&r1=1841925&r2=1841926&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexStatisticsTest.java (original) +++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexStatisticsTest.java Tue Sep 25 12:24:15 2018 @@ -17,6 +17,7 @@ package org.apache.jackrabbit.oak.plugins.index.lucene; import com.google.common.collect.Lists; +import org.apache.jackrabbit.oak.plugins.index.search.FieldNames; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.StringField; @@ -34,21 +35,21 @@ import java.io.IOException; import java.util.Collections; import java.util.List; -import static org.apache.jackrabbit.oak.plugins.index.lucene.IndexStatistics.SYNTHETICALLY_FALLIABLE_FIELD; +import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexStatistics.SYNTHETICALLY_FALLIABLE_FIELD; import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.VERSION; import static org.junit.Assert.assertEquals; public class IndexStatisticsTest { @After public void resetFailFlags() { - IndexStatistics.failReadingFields = false; - IndexStatistics.failReadingSyntheticallyFalliableField = false; + LuceneIndexStatistics.failReadingFields = false; + LuceneIndexStatistics.failReadingSyntheticallyFalliableField = false; } @Test public void numDocs() throws Exception { Directory d = createSampleDirectory(2); - IndexStatistics stats = getStats(d); + LuceneIndexStatistics stats = getStats(d); assertEquals(2, stats.numDocs()); } @@ -62,14 +63,14 @@ public class IndexStatisticsTest { writer.close(); } - IndexStatistics stats = getStats(d); + LuceneIndexStatistics stats = getStats(d); assertEquals(1, stats.numDocs()); } @Test public void getSimpleFieldDocCnt() throws Exception { Directory d = createSampleDirectory(2); - IndexStatistics stats = getStats(d); + LuceneIndexStatistics stats = getStats(d); assertEquals(2, stats.getDocCountFor("foo")); } @@ -83,15 +84,15 @@ public class IndexStatisticsTest { writer.close(); } - IndexStatistics stats = getStats(d); + LuceneIndexStatistics stats = getStats(d); assertEquals("Stats don't need to get accurate result which might require reading more", - 2, stats.getDocCountFor("foo")); + 2, stats.getDocCountFor("foo")); } @Test public void absentFields() throws Exception { Directory d = createSampleDirectory(1); - IndexStatistics stats = getStats(d); + LuceneIndexStatistics stats = getStats(d); assertEquals(1, stats.getDocCountFor("foo")); assertEquals(0, stats.getDocCountFor("absent")); @@ -110,7 +111,7 @@ public class IndexStatisticsTest { document.add(new StringField(FieldNames.FULLTEXT_RELATIVE_NODE + "foo", "manualBar", Field.Store.NO)); document.add(new StringField("foo_facet", "manualBar", Field.Store.NO)); Directory d = createSampleDirectory(document); - IndexStatistics stats = getStats(d); + LuceneIndexStatistics stats = getStats(d); assertEquals(3, stats.getDocCountFor("foo")); assertEquals(0, stats.getDocCountFor("absent")); @@ -122,9 +123,9 @@ public class IndexStatisticsTest { @Test public void unableToIterateFields() throws Exception { - IndexStatistics.failReadingFields = true; + LuceneIndexStatistics.failReadingFields = true; - IndexStatistics stats = getStats(createSampleDirectory(100)); + LuceneIndexStatistics stats = getStats(createSampleDirectory(100)); assertEquals(100, stats.numDocs()); assertEquals(-1, stats.getDocCountFor("foo")); @@ -133,12 +134,12 @@ public class IndexStatisticsTest { @Test public void unableToReadCountForJcrTitle() throws Exception { - IndexStatistics.failReadingSyntheticallyFalliableField = true; + LuceneIndexStatistics.failReadingSyntheticallyFalliableField = true; Document doc = new Document(); doc.add(new StringField("foo1", "bar1", Field.Store.NO)); doc.add(new StringField(SYNTHETICALLY_FALLIABLE_FIELD, "title", Field.Store.NO)); - IndexStatistics stats = getStats(createSampleDirectory(doc)); + LuceneIndexStatistics stats = getStats(createSampleDirectory(doc)); assertEquals(3, stats.numDocs()); assertEquals(2, stats.getDocCountFor("foo")); @@ -187,12 +188,12 @@ public class IndexStatisticsTest { return new IndexWriter(d, config); } - private static IndexStatistics getStats(Directory d) throws IOException { + private static LuceneIndexStatistics getStats(Directory d) throws IOException { IndexReader reader = DirectoryReader.open(d); // no more reads d.close(); - IndexStatistics stats = new IndexStatistics(reader); + LuceneIndexStatistics stats = new LuceneIndexStatistics(reader); //close reader... Index stats would read numDocs right away reader.close();
Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexTrackerTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexTrackerTest.java?rev=1841926&r1=1841925&r2=1841926&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexTrackerTest.java (original) +++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexTrackerTest.java Tue Sep 25 12:24:15 2018 @@ -29,6 +29,8 @@ import org.apache.jackrabbit.oak.commons import org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoService; import org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider; import org.apache.jackrabbit.oak.plugins.index.TrackingCorruptIndexHandler; +import org.apache.jackrabbit.oak.plugins.index.search.BadIndexTracker; +import org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition; import org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob; import org.apache.jackrabbit.oak.plugins.memory.ModifiedNodeState; import org.apache.jackrabbit.oak.plugins.memory.PropertyStates; @@ -36,12 +38,10 @@ import org.apache.jackrabbit.oak.spi.com import org.apache.jackrabbit.oak.spi.commit.EditorHook; import org.apache.jackrabbit.oak.spi.state.NodeBuilder; import org.apache.jackrabbit.oak.spi.state.NodeState; -import org.apache.jackrabbit.oak.plugins.index.lucene.BadIndexTracker.BadIndexInfo; import org.junit.Before; import org.junit.Test; import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME; -import static org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition.STATUS_NODE; import static org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition; import static org.apache.jackrabbit.oak.InitialContentHelper.INITIAL_CONTENT; import static org.junit.Assert.assertEquals; @@ -68,7 +68,7 @@ public class IndexTrackerTest { @Before public void setUp(){ IndexUpdateProvider updateProvider = new IndexUpdateProvider( - new LuceneIndexEditorProvider(), "async", false); + new LuceneIndexEditorProvider(), "async", false); updateProvider.setCorruptIndexHandler(corruptIndexHandler); hook = new EditorHook(updateProvider); } @@ -87,7 +87,7 @@ public class IndexTrackerTest { assertEquals(0, tracker.getIndexNodePaths().size()); tracker.update(indexed); - IndexNode indexNode = tracker.acquireIndexNode("/oak:index/lucene"); + LuceneIndexNode indexNode = tracker.acquireIndexNode("/oak:index/lucene"); indexNode.release(); assertEquals(1, tracker.getIndexNodePaths().size()); @@ -111,7 +111,7 @@ public class IndexTrackerTest { NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY); tracker.update(indexed); - IndexNode indexNode = tracker.acquireIndexNode("/oak:index/foo"); + LuceneIndexNode indexNode = tracker.acquireIndexNode("/oak:index/foo"); indexNode.release(); assertTrue(tracker.getBadIndexTracker().getIndexPaths().isEmpty()); @@ -130,7 +130,7 @@ public class IndexTrackerTest { //3. Recreate the tracker as we cannot push corrupt index in existing tracker - //As diffAndUpdate would fail and existing IndexNode would not be changed + //As diffAndUpdate would fail and existing LuceneIndexNode would not be changed tracker = new IndexTracker(); tracker.update(indexed); @@ -143,7 +143,7 @@ public class IndexTrackerTest { assertNull(indexNode); assertTrue(tracker.getBadIndexTracker().getIndexPaths().contains("/oak:index/foo")); - BadIndexInfo badIdxInfo = tracker.getBadIndexTracker().getInfo("/oak:index/foo"); + BadIndexTracker.BadIndexInfo badIdxInfo = tracker.getBadIndexTracker().getInfo("/oak:index/foo"); assertNotNull(badIdxInfo); assertEquals(0, badIdxInfo.getAccessCount()); @@ -209,7 +209,7 @@ public class IndexTrackerTest { assertTrue(corruptIndexHandler.getFailingIndexData("async").containsKey("/oak:index/foo")); } - + @Test public void avoidRedundantDiff() throws Exception{ IndexTracker tracker2 = new IndexTracker(); @@ -226,7 +226,7 @@ public class IndexTrackerTest { tracker.update(indexed); tracker2.update(indexed); - IndexNode indexNode = tracker.acquireIndexNode("/oak:index/lucene"); + LuceneIndexNode indexNode = tracker.acquireIndexNode("/oak:index/lucene"); assertEquals(1, indexNode.getSearcher().getIndexReader().numDocs()); indexNode.release(); @@ -269,7 +269,7 @@ public class IndexTrackerTest { indexed = ModifiedNodeState.squeeze(indexed); tracker.update(indexed); - IndexNode indexNode = tracker.acquireIndexNode("/oak:index/lucene"); + LuceneIndexNode indexNode = tracker.acquireIndexNode("/oak:index/lucene"); int indexNodeId = indexNode.getIndexNodeId(); indexNode.release(); @@ -293,7 +293,7 @@ public class IndexTrackerTest { for (String name : dir.getChildNodeNames()){ if (!"segments.gen".equals(name)){ dir.getChildNode(name).setProperty(PropertyStates.createProperty("jcr:data", Collections - .singletonList(new ArrayBasedBlob("foo".getBytes())), Type.BINARIES)); + .singletonList(new ArrayBasedBlob("foo".getBytes())), Type.BINARIES)); } } Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LowCostLuceneIndexProvider.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LowCostLuceneIndexProvider.java?rev=1841926&r1=1841925&r2=1841926&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LowCostLuceneIndexProvider.java (original) +++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LowCostLuceneIndexProvider.java Tue Sep 25 12:24:15 2018 @@ -46,7 +46,7 @@ public class LowCostLuceneIndexProvider @Override public List<IndexPlan> getPlans(Filter filter, List<OrderEntry> sortOrder, NodeState rootState) { - String indexPath = new LuceneIndexLookup(rootState).getOldFullTextIndexPath(filter, tracker); + String indexPath = LuceneIndexLookupUtil.getOldFullTextIndexPath(rootState, filter, tracker); if (indexPath == null){ return Collections.emptyList(); } Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneBlobCacheTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneBlobCacheTest.java?rev=1841926&r1=1841925&r2=1841926&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneBlobCacheTest.java (original) +++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneBlobCacheTest.java Tue Sep 25 12:24:15 2018 @@ -19,20 +19,13 @@ package org.apache.jackrabbit.oak.plugins.index.lucene; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.Random; - import org.apache.jackrabbit.core.data.DataIdentifier; import org.apache.jackrabbit.core.data.DataRecord; import org.apache.jackrabbit.core.data.DataStoreException; import org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore; import org.apache.jackrabbit.oak.plugins.blob.datastore.OakFileDataStore; import org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory; +import org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition; import org.apache.jackrabbit.oak.segment.SegmentNodeStoreBuilders; import org.apache.jackrabbit.oak.segment.file.FileStore; import org.apache.jackrabbit.oak.segment.file.FileStoreBuilder; @@ -49,71 +42,79 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.Random; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + public class LuceneBlobCacheTest { private Random rnd = new Random(); - + @Rule public final TemporaryFolder tempFolder = new TemporaryFolder(new File("target")); - + FileStore store; ReadAccessCountingDataStore fileDataStore; NodeBuilder builder; NodeState root; - - @Before + + @Before public void setUp() throws Exception { fileDataStore = new ReadAccessCountingDataStore(); fileDataStore.init(tempFolder.newFolder().getAbsolutePath()); FileStoreBuilder fileStoreBuilder = FileStoreBuilder.fileStoreBuilder(tempFolder.newFolder()) - .withBlobStore(new DataStoreBlobStore(fileDataStore)).withMaxFileSize(256) - .withSegmentCacheSize(64).withMemoryMapping(false); + .withBlobStore(new DataStoreBlobStore(fileDataStore)).withMaxFileSize(256) + .withSegmentCacheSize(64).withMemoryMapping(false); store = fileStoreBuilder.build(); NodeStore nodeStore = SegmentNodeStoreBuilders.builder(store).build(); root = nodeStore.getRoot(); builder = root.builder(); } - + @Test public void testLuceneBlobCached() throws Exception { Directory dir = createDir(builder, false); assertWrites(dir, IndexDefinition.DEFAULT_BLOB_SIZE); } - + @After public void close() throws Exception { if (store != null) { store.close(); } - } + } byte[] assertWrites(Directory dir, int blobSize) throws IOException { byte[] data = randomBytes(blobSize); IndexOutput o = dir.createOutput("test", IOContext.DEFAULT); o.writeBytes(data, data.length); o.close(); - + IndexInput i = dir.openInput("test", IOContext.DEFAULT); assertEquals(blobSize, i.length()); byte[] result = new byte[blobSize]; i.readBytes(result, 0, result.length); assertTrue(Arrays.equals(data, result)); - + // Load agagin to see if cached i = dir.openInput("test", IOContext.DEFAULT); assertEquals(blobSize, i.length()); result = new byte[blobSize]; i.readBytes(result, 0, result.length); assertTrue(Arrays.equals(data, result)); - + assertEquals(1, fileDataStore.count); - + return data; } private Directory createDir(NodeBuilder builder, boolean readOnly){ return new OakDirectory(builder, - new IndexDefinition(root, builder.getNodeState(), "/foo"), readOnly); + new LuceneIndexDefinition(root, builder.getNodeState(), "/foo"), readOnly); } byte[] randomBytes(int size) { @@ -121,10 +122,10 @@ public class LuceneBlobCacheTest { rnd.nextBytes(data); return data; } - + class ReadAccessCountingDataStore extends OakFileDataStore { int count; - + @Override public DataRecord getRecord(DataIdentifier identifier) throws DataStoreException { count++; Added: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneDocumentMakerTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneDocumentMakerTest.java?rev=1841926&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneDocumentMakerTest.java (added) +++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneDocumentMakerTest.java Tue Sep 25 12:24:15 2018 @@ -0,0 +1,67 @@ +/* + * 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.api.Type; +import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneDocumentMaker; +import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexDefinition; +import org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder; +import org.apache.jackrabbit.oak.spi.state.NodeBuilder; +import org.apache.jackrabbit.oak.spi.state.NodeState; +import org.junit.Test; + +import static java.util.Arrays.asList; +import static org.apache.jackrabbit.oak.InitialContentHelper.INITIAL_CONTENT; +import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +public class LuceneDocumentMakerTest { + private NodeState root = INITIAL_CONTENT; + private IndexDefinitionBuilder builder = new IndexDefinitionBuilder(); + + @Test + public void excludeSingleProperty() throws Exception{ + builder.indexRule("nt:base") + .property("foo") + .propertyIndex() + .analyzed() + .valueExcludedPrefixes("/jobs"); + + LuceneIndexDefinition defn = LuceneIndexDefinition.newBuilder(root, builder.build(), "/foo").build(); + LuceneDocumentMaker docMaker = new LuceneDocumentMaker(defn, + defn.getApplicableIndexingRule("nt:base"), "/x"); + + NodeBuilder test = EMPTY_NODE.builder(); + test.setProperty("foo", "bar"); + + assertNotNull(docMaker.makeDocument(test.getNodeState())); + + test.setProperty("foo", "/jobs/a"); + assertNull(docMaker.makeDocument(test.getNodeState())); + + test.setProperty("foo", asList("/a", "/jobs/a"), Type.STRINGS); + assertNotNull(docMaker.makeDocument(test.getNodeState())); + + test.setProperty("foo", asList("/jobs/a"), Type.STRINGS); + assertNull(docMaker.makeDocument(test.getNodeState())); + } + +} \ No newline at end of file Propchange: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneDocumentMakerTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexAggregation2Test.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexAggregation2Test.java?rev=1841926&r1=1841925&r2=1841926&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexAggregation2Test.java (original) +++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexAggregation2Test.java Tue Sep 25 12:24:15 2018 @@ -52,6 +52,7 @@ import org.apache.jackrabbit.oak.api.Res import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.plugins.index.aggregate.SimpleNodeAggregator; +import org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants; import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore; import org.apache.jackrabbit.oak.plugins.memory.PropertyStates; import org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider; @@ -82,16 +83,16 @@ import com.google.common.collect.Lists; public class LuceneIndexAggregation2Test extends AbstractQueryTest { private static final Logger LOG = LoggerFactory.getLogger(LuceneIndexAggregation2Test.class); - + private static final String NT_TEST_PAGE = "test:Page"; private static final String NT_TEST_PAGECONTENT = "test:PageContent"; private static final String NT_TEST_ASSET = "test:Asset"; private static final String NT_TEST_ASSETCONTENT = "test:AssetContent"; - + @Override protected ContentRepository createRepository() { LuceneIndexProvider provider = new LuceneIndexProvider(); - + return new Oak() .with(new InitialContent() { @@ -137,10 +138,10 @@ public class LuceneIndexAggregation2Test .with((Observer) provider).with(new LuceneIndexEditorProvider()) .createContentRepository(); } - + /** * convenience method for printing on logs the currently registered node types. - * + * * @param builder */ private static void printNodeTypes(NodeBuilder builder) { @@ -150,7 +151,7 @@ public class LuceneIndexAggregation2Test Collections.sort(nodes); for (String node : nodes) { LOG.debug(node); - } + } } } @@ -161,33 +162,33 @@ public class LuceneIndexAggregation2Test useV2(indexDefn); //Aggregates newNodeAggregator(indexDefn) - .newRuleWithName(NT_FILE, newArrayList("jcr:content")) - .newRuleWithName(NT_TEST_PAGE, newArrayList("jcr:content")) - .newRuleWithName(NT_TEST_PAGECONTENT, newArrayList("*", "*/*", "*/*/*", "*/*/*/*")) - .newRuleWithName(NT_TEST_ASSET, newArrayList("jcr:content")) - .newRuleWithName( - NT_TEST_ASSETCONTENT, - newArrayList("metadata", "renditions", "renditions/original", "comments", - "renditions/original/jcr:content")) - .newRuleWithName("rep:User", newArrayList("profile")); - - Tree originalInclude = indexDefn.getChild(LuceneIndexConstants.AGGREGATES) - .getChild(NT_TEST_ASSET).addChild("includeOriginal"); - originalInclude.setProperty(LuceneIndexConstants.AGG_RELATIVE_NODE, true); - originalInclude.setProperty(LuceneIndexConstants.AGG_PATH, "jcr:content/renditions/original"); + .newRuleWithName(NT_FILE, newArrayList("jcr:content")) + .newRuleWithName(NT_TEST_PAGE, newArrayList("jcr:content")) + .newRuleWithName(NT_TEST_PAGECONTENT, newArrayList("*", "*/*", "*/*/*", "*/*/*/*")) + .newRuleWithName(NT_TEST_ASSET, newArrayList("jcr:content")) + .newRuleWithName( + NT_TEST_ASSETCONTENT, + newArrayList("metadata", "renditions", "renditions/original", "comments", + "renditions/original/jcr:content")) + .newRuleWithName("rep:User", newArrayList("profile")); - Tree includeSingleRel = indexDefn.getChild(LuceneIndexConstants.AGGREGATES) + Tree originalInclude = indexDefn.getChild(FulltextIndexConstants.AGGREGATES) + .getChild(NT_TEST_ASSET).addChild("includeOriginal"); + originalInclude.setProperty(FulltextIndexConstants.AGG_RELATIVE_NODE, true); + originalInclude.setProperty(FulltextIndexConstants.AGG_PATH, "jcr:content/renditions/original"); + + Tree includeSingleRel = indexDefn.getChild(FulltextIndexConstants.AGGREGATES) .getChild(NT_TEST_ASSET).addChild("includeFirstLevelChild"); - includeSingleRel.setProperty(LuceneIndexConstants.AGG_RELATIVE_NODE, true); - includeSingleRel.setProperty(LuceneIndexConstants.AGG_PATH, "firstLevelChild"); + includeSingleRel.setProperty(FulltextIndexConstants.AGG_RELATIVE_NODE, true); + includeSingleRel.setProperty(FulltextIndexConstants.AGG_PATH, "firstLevelChild"); // Include all properties for both assets and pages Tree assetProps = TestUtil.newRulePropTree(indexDefn, NT_TEST_ASSET); TestUtil.enableForFullText(assetProps, "jcr:content/metadata/format"); - TestUtil.enableForFullText(assetProps, LuceneIndexConstants.REGEX_ALL_PROPS, true); + TestUtil.enableForFullText(assetProps, FulltextIndexConstants.REGEX_ALL_PROPS, true); Tree pageProps = TestUtil.newRulePropTree(indexDefn, NT_TEST_PAGE); - TestUtil.enableForFullText(pageProps, LuceneIndexConstants.REGEX_ALL_PROPS, true); + TestUtil.enableForFullText(pageProps, FulltextIndexConstants.REGEX_ALL_PROPS, true); root.commit(); } @@ -204,7 +205,7 @@ public class LuceneIndexAggregation2Test "renditions/original/jcr:content")) .newRuleWithName("rep:User", newArrayList("profile")); } - + @Test public void oak2226() throws Exception { setTraversalEnabled(false); @@ -213,7 +214,7 @@ public class LuceneIndexAggregation2Test "and (jcr:contains(jcr:content/metadata/@format, 'image'))]"; Tree content = root.getTree("/").addChild("content"); List<String> expected = Lists.newArrayList(); - + /* * creating structure * "/content" : { @@ -240,8 +241,8 @@ public class LuceneIndexAggregation2Test * } * } */ - - + + // adding a node with 'mountain' property Tree node = content.addChild("node"); node.setProperty(JCR_PRIMARYTYPE, NT_TEST_ASSET, NAME); @@ -252,7 +253,7 @@ public class LuceneIndexAggregation2Test node.setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME); node.setProperty("title", "Lorem mountain ipsum", STRING); node.setProperty("format", "image/jpeg", STRING); - + // adding a node with 'mountain' name but not property node = content.addChild("mountain-node"); node.setProperty(JCR_PRIMARYTYPE, NT_TEST_ASSET, NAME); @@ -262,7 +263,7 @@ public class LuceneIndexAggregation2Test node = node.addChild("metadata"); node.setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME); node.setProperty("format", "image/jpeg", STRING); - + root.commit(); assertQuery(statement, "xpath", expected); @@ -274,21 +275,21 @@ public class LuceneIndexAggregation2Test setTraversalEnabled(false); final String statement = "//element(*, test:Asset)[ " + "( " + - "jcr:contains(., 'summer') " + - "or " + - "jcr:content/metadata/@tags = 'namespace:season/summer' " + + "jcr:contains(., 'summer') " + + "or " + + "jcr:content/metadata/@tags = 'namespace:season/summer' " + ") and " + - "jcr:contains(jcr:content/metadata/@format, 'image') " + - "]"; - + "jcr:contains(jcr:content/metadata/@format, 'image') " + + "]"; + Tree content = root.getTree("/").addChild("content"); List<String> expected = newArrayList(); - + Tree metadata = createAssetStructure(content, "tagged"); metadata.setProperty("tags", of("namespace:season/summer"), STRINGS); metadata.setProperty("format", "image/jpeg", STRING); expected.add("/content/tagged"); - + metadata = createAssetStructure(content, "titled"); metadata.setProperty("title", "Lorem summer ipsum", STRING); metadata.setProperty("format", "image/jpeg", STRING); @@ -297,7 +298,7 @@ public class LuceneIndexAggregation2Test metadata = createAssetStructure(content, "summer-node"); metadata.setProperty("format", "image/jpeg", STRING); expected.add("/content/summer-node"); - + // the following is NOT expected metadata = createAssetStructure(content, "winter-node"); metadata.setProperty("tags", of("namespace:season/winter"), STRINGS); @@ -305,7 +306,7 @@ public class LuceneIndexAggregation2Test metadata.setProperty("format", "image/jpeg", STRING); root.commit(); - + assertQuery(statement, "xpath", expected); setTraversalEnabled(true); } @@ -314,10 +315,10 @@ public class LuceneIndexAggregation2Test public void indexRelativeNode() throws Exception { setTraversalEnabled(false); final String statement = "//element(*, test:Asset)[ " + - "jcr:contains(., 'summer') " + - "and jcr:contains(jcr:content/renditions/original, 'fox')" + - "and jcr:contains(jcr:content/metadata/@format, 'image') " + - "]"; + "jcr:contains(., 'summer') " + + "and jcr:contains(jcr:content/renditions/original, 'fox')" + + "and jcr:contains(jcr:content/metadata/@format, 'image') " + + "]"; Tree content = root.getTree("/").addChild("content"); List<String> expected = newArrayList(); @@ -373,12 +374,12 @@ public class LuceneIndexAggregation2Test Tree pageContent = createPageStructure(content, "foo"); // contains 'aliq' but not 'tinc' pageContent.setProperty("bar", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque aliquet odio varius odio " - + "imperdiet, non egestas ex consectetur. Fusce congue ac augue quis finibus. Sed vulputate sollicitudin neque, nec " - + "lobortis nisl varius eget."); + + "imperdiet, non egestas ex consectetur. Fusce congue ac augue quis finibus. Sed vulputate sollicitudin neque, nec " + + "lobortis nisl varius eget."); // doesn't contain 'aliq' but 'tinc' pageContent.getParent().setProperty("bar", "Donec lacinia luctus leo, sed rutrum nulla. Sed sed hendrerit turpis. Donec ex quam, " - + "bibendum et metus at, tristique tincidunt leo. Nam at elit ligula. Etiam ullamcorper, elit sit amet varius molestie, " - + "nisl ex egestas libero, quis elementum enim mi a quam."); + + "bibendum et metus at, tristique tincidunt leo. Nam at elit ligula. Etiam ullamcorper, elit sit amet varius molestie, " + + "nisl ex egestas libero, quis elementum enim mi a quam."); root.commit(); @@ -399,7 +400,7 @@ public class LuceneIndexAggregation2Test * <p> * convenience method that create an "asset" structure like * </p> - * + * * <pre> * "parent" : { * "nodeName" : { @@ -413,20 +414,20 @@ public class LuceneIndexAggregation2Test * } * } * </pre> - * + * * <p> * and returns the {@code metadata} node * </p> - * + * * @param parent the parent under which creating the node * @param nodeName the node name to be used * @return the {@code metadata} node. See above for details */ - private static Tree createAssetStructure(@NotNull final Tree parent, + private static Tree createAssetStructure(@NotNull final Tree parent, @NotNull final String nodeName) { checkNotNull(parent); checkArgument(!Strings.isNullOrEmpty(nodeName), "nodeName cannot be null or empty"); - + Tree node = parent.addChild(nodeName); node.setProperty(JCR_PRIMARYTYPE, NT_TEST_ASSET, NAME); node = node.addChild(JCR_CONTENT); Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexAggregationTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexAggregationTest.java?rev=1841926&r1=1841925&r2=1841926&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexAggregationTest.java (original) +++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexAggregationTest.java Tue Sep 25 12:24:15 2018 @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.Calendar; import org.apache.jackrabbit.JcrConstants; +import org.apache.jackrabbit.oak.InitialContentHelper; import org.apache.jackrabbit.oak.Oak; import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.ContentRepository; @@ -35,7 +36,7 @@ import org.apache.jackrabbit.oak.api.Tre import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.plugins.index.IndexConstants; import org.apache.jackrabbit.oak.plugins.index.aggregate.SimpleNodeAggregator; -import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore; +import org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants; import static org.apache.jackrabbit.oak.plugins.index.lucene.TestUtil.newNodeAggregator; import static org.apache.jackrabbit.oak.plugins.index.lucene.TestUtil.useV2; @@ -43,7 +44,7 @@ import static org.apache.jackrabbit.oak. import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import org.apache.jackrabbit.oak.InitialContentHelper; +import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore; import org.apache.jackrabbit.oak.query.AbstractQueryTest; import org.apache.jackrabbit.oak.spi.commit.Observer; import org.apache.jackrabbit.oak.spi.query.QueryIndex; @@ -67,7 +68,7 @@ public class LuceneIndexAggregationTest //Include all properties Tree props = TestUtil.newRulePropTree(indexDefn, "nt:base"); - TestUtil.enableForFullText(props, LuceneIndexConstants.REGEX_ALL_PROPS, true); + TestUtil.enableForFullText(props, FulltextIndexConstants.REGEX_ALL_PROPS, true); root.commit(); } @@ -85,13 +86,13 @@ public class LuceneIndexAggregationTest /** * <code> - * <aggregate primaryType="nt:file"> + * <aggregate primaryType="nt:file"> * <include>jcr:content</include> * <include>jcr:content/*</include> * <include-property>jcr:content/jcr:lastModified</include-property> * </aggregate> * <code> - * + * */ private static QueryIndex.NodeAggregator getNodeAggregator() { return new SimpleNodeAggregator() @@ -101,7 +102,7 @@ public class LuceneIndexAggregationTest /** * simple index aggregation from jcr:content to nt:file - * + * */ @Test public void testNtFileAggregate() throws Exception { @@ -400,15 +401,15 @@ public class LuceneIndexAggregationTest root.commit(); assertQuery( - "//element(*, nt:file)[jcr:contains(., 'dog')]", + "//element(*, nt:file)[jcr:contains(., 'dog')]", "xpath", ImmutableList.of("/myFolder/myFile")); assertQuery( - "//element(*, nt:file)[jcr:contains(., 'title')]", + "//element(*, nt:file)[jcr:contains(., 'title')]", "xpath", ImmutableList.of("/myFolder/myFile")); assertQuery( - "//element(*, nt:file)[jcr:contains(., 'dog') and jcr:contains(., 'title')]", + "//element(*, nt:file)[jcr:contains(., 'dog') and jcr:contains(., 'title')]", "xpath", ImmutableList.of("/myFolder/myFile")); // double aggregation dupes @@ -424,21 +425,21 @@ public class LuceneIndexAggregationTest @Test public void oak3371AggregateV1() throws CommitFailedException { - + Tree indexdef = root.getTree("/oak:index/" + TEST_INDEX_NAME); assertNotNull(indexdef); assertTrue(indexdef.exists()); - indexdef.setProperty(LuceneIndexConstants.COMPAT_MODE, 1L); + indexdef.setProperty(FulltextIndexConstants.COMPAT_MODE, 1L); indexdef.setProperty(IndexConstants.REINDEX_PROPERTY_NAME, true); root.commit(); - + oak3371(); } private void oak3371() throws CommitFailedException { setTraversalEnabled(false); Tree test, t; - + test = root.getTree("/").addChild("test"); t = test.addChild("a"); t.setProperty(JCR_PRIMARYTYPE, NT_FOLDER, Type.NAME); @@ -452,7 +453,7 @@ public class LuceneIndexAggregationTest t.setProperty(JCR_PRIMARYTYPE, NT_FOLDER, Type.NAME); t.setProperty("foo", "bar cat"); root.commit(); - + assertQuery( "SELECT * FROM [nt:folder] WHERE ISDESCENDANTNODE('/test') AND CONTAINS(foo, 'bar')", of("/test/a", "/test/d")); Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexAugmentTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexAugmentTest.java?rev=1841926&r1=1841925&r2=1841926&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexAugmentTest.java (original) +++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexAugmentTest.java Tue Sep 25 12:24:15 2018 @@ -31,6 +31,8 @@ import org.apache.jackrabbit.oak.plugins import org.apache.jackrabbit.oak.plugins.index.lucene.score.ScorerProviderFactory; import org.apache.jackrabbit.oak.plugins.index.lucene.spi.FulltextQueryTermsProvider; import org.apache.jackrabbit.oak.plugins.index.lucene.spi.IndexFieldProvider; +import org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants; +import org.apache.jackrabbit.oak.plugins.index.search.ExtractedTextCache; import org.apache.jackrabbit.oak.plugins.nodetype.write.NodeTypeRegistry; import org.apache.jackrabbit.oak.query.AbstractQueryTest; import org.apache.jackrabbit.oak.spi.commit.Observer; @@ -64,7 +66,7 @@ public class LuceneIndexAugmentTest exte private IndexTracker tracker = new IndexTracker(); - private IndexNode indexNode; + private LuceneIndexNode indexNode; @Override protected void createTestIndexNode() throws Exception { @@ -74,17 +76,17 @@ public class LuceneIndexAugmentTest exte @Override protected ContentRepository createRepository() { LuceneIndexEditorProvider editorProvider = new LuceneIndexEditorProvider(null, - new ExtractedTextCache(0, 0), - factory, Mounts.defaultMountInfoProvider()); + new ExtractedTextCache(0, 0), + factory, Mounts.defaultMountInfoProvider()); LuceneIndexProvider provider = new LuceneIndexProvider(tracker, - ScorerProviderFactory.DEFAULT, - factory); + ScorerProviderFactory.DEFAULT, + factory); return new Oak() - .with(new OpenSecurityProvider()) - .with((QueryIndexProvider) provider) - .with((Observer) provider) - .with(editorProvider) - .createContentRepository(); + .with(new OpenSecurityProvider()) + .with((QueryIndexProvider) provider) + .with((Observer) provider) + .with(editorProvider) + .createContentRepository(); } //OAK-3576 @@ -102,7 +104,7 @@ public class LuceneIndexAugmentTest exte @Override public Query getQueryTerm(String text, Analyzer analyzer, NodeState indexDefinition) { assertEquals("Full text term passed to provider isn't same as the one passed in query", - testSearchText, text); + testSearchText, text); return new TermQuery(new Term(":fulltext", realSearchText)); } @@ -190,7 +192,7 @@ public class LuceneIndexAugmentTest exte assertEquals("/test/item", path); assertEquals(TestUtil.NT_TEST, document.getName(JcrConstants.JCR_PRIMARYTYPE)); assertEquals(IndexConstants.INDEX_DEFINITIONS_NODE_TYPE, - indexDefinition.getName(JcrConstants.JCR_PRIMARYTYPE)); + indexDefinition.getName(JcrConstants.JCR_PRIMARYTYPE)); return Lists.<Field>newArrayList(new StringField("barbar", "1", Field.Store.NO)); } @@ -347,10 +349,10 @@ public class LuceneIndexAugmentTest exte NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType"); Tree props = createIndex(TestUtil.NT_TEST); Tree prop = props.addChild("foo1"); - prop.setProperty(LuceneIndexConstants.PROP_INDEX, true); + prop.setProperty(FulltextIndexConstants.PROP_INDEX, true); prop = props.addChild("foo2"); - prop.setProperty(LuceneIndexConstants.PROP_NAME, "subChild/foo2"); - prop.setProperty(LuceneIndexConstants.PROP_INDEX, true); + prop.setProperty(FulltextIndexConstants.PROP_NAME, "subChild/foo2"); + prop.setProperty(FulltextIndexConstants.PROP_INDEX, true); root.commit(); //setup augmentors @@ -393,17 +395,17 @@ public class LuceneIndexAugmentTest exte //indexing assertions assertEquals("Indexing augment should get called once", 1, indexingCounter.get()); assertEquals("No docs should get indexed (augmentor hasn't added any field)", - 0, getSearcher().getIndexReader().numDocs()); + 0, getSearcher().getIndexReader().numDocs()); String query = "EXPLAIN SELECT [jcr:path] from [" + TestUtil.NT_TEST + "] WHERE [foo1]='bar1'"; List<String> paths = executeQuery(query, SQL2); assertTrue("indexed prop name shouldn't decide query plan (" + paths.get(0) + ")", - paths.get(0).contains("/* no-index ")); + paths.get(0).contains("/* no-index ")); query = "EXPLAIN SELECT [jcr:path] from [" + TestUtil.NT_TEST + "] WHERE [subChild/foo2]='bar2'"; paths = executeQuery(query, SQL2); assertTrue("indexed prop name shouldn't decide query plan (" + paths.get(0) + ")", - paths.get(0).contains("/* no-index ")); + paths.get(0).contains("/* no-index ")); } //OAK-3576 @@ -462,7 +464,7 @@ public class LuceneIndexAugmentTest exte query = "EXPLAIN " + query; List<String> paths = executeQuery(query, SQL2, false); assertTrue("property index should have made the index selected (" + paths.get(0) + ")", - paths.get(0).contains("/* lucene:test-index(")); + paths.get(0).contains("/* lucene:test-index(")); query = "SELECT [jcr:path] from [" + TestUtil.NT_TEST + "] WHERE [subChild/foo2]='bar2'"; executeQuery(query, SQL2); @@ -470,7 +472,7 @@ public class LuceneIndexAugmentTest exte query = "EXPLAIN " + query; paths = executeQuery(query, SQL2); assertTrue("property index should have made the index selected (" + paths.get(0) + ")", - paths.get(0).contains("/* lucene:test-index(")); + paths.get(0).contains("/* lucene:test-index(")); } //OAK-3576 @@ -531,7 +533,7 @@ public class LuceneIndexAugmentTest exte List<String> paths = executeQuery(query, SQL2, false); assertEquals("Query augmentor should get called for full text constraints", 1, queryingCounter.get()); assertTrue("property index should have made the index selected (" + paths.get(0) + ")", - paths.get(0).contains("/* lucene:test-index(")); + paths.get(0).contains("/* lucene:test-index(")); queryingCounter.set(0); query = "SELECT [jcr:path] from [" + TestUtil.NT_TEST + "] WHERE CONTAINS(*, 'bar2')"; @@ -542,7 +544,7 @@ public class LuceneIndexAugmentTest exte paths = executeQuery(query, SQL2, false); assertEquals("Query augmentor should get called for full text constraints", 1, queryingCounter.get()); assertTrue("property index should have made the index selected (" + paths.get(0) + ")", - paths.get(0).contains("/* lucene:test-index(")); + paths.get(0).contains("/* lucene:test-index(")); } @Test @@ -674,20 +676,20 @@ public class LuceneIndexAugmentTest exte @Override public IndexFieldProvider getIndexFieldProvider(String nodeType) { return useSuperBehavior? - super.getIndexFieldProvider(nodeType): - (indexFieldProvider != null)? - indexFieldProvider: - IndexFieldProvider.DEFAULT; + super.getIndexFieldProvider(nodeType): + (indexFieldProvider != null)? + indexFieldProvider: + IndexFieldProvider.DEFAULT; } @NotNull @Override public FulltextQueryTermsProvider getFulltextQueryTermsProvider(String nodeType) { return useSuperBehavior? - super.getFulltextQueryTermsProvider(nodeType): - (fulltextQueryTermsProvider != null)? - fulltextQueryTermsProvider: - FulltextQueryTermsProvider.DEFAULT; + super.getFulltextQueryTermsProvider(nodeType): + (fulltextQueryTermsProvider != null)? + fulltextQueryTermsProvider: + FulltextQueryTermsProvider.DEFAULT; } } @@ -700,7 +702,7 @@ public class LuceneIndexAugmentTest exte private void checkSimpleBehavior(Tree rootTree, int testIndex) throws Exception { createNodeWithType(rootTree, "node" + testIndex, TestUtil.NT_TEST) - .setProperty("foo", "bar" + testIndex); + .setProperty("foo", "bar" + testIndex); root.commit(); String query = "SELECT [jcr:path] from [" + TestUtil.NT_TEST + "] WHERE contains(*, 'bar" + testIndex + "')";
