Skip to content

Commit

Permalink
OAK-7147 - Oak run LuceneIndexer indexes excluded parent nodes
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/oak/trunk@1820947 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
chetanmeh committed Jan 12, 2018
1 parent b63b473 commit a96c2ba
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ public boolean shouldInclude(NodeDocument doc) {
}

@Override
public void index(NodeStateEntry entry) throws IOException, CommitFailedException {
public boolean index(NodeStateEntry entry) throws IOException, CommitFailedException {
boolean result = false;
for (NodeStateIndexer indexer : indexers) {
indexer.index(entry);
result |= indexer.index(entry);
}
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public LuceneIndexer(IndexDefinition definition, LuceneIndexWriter indexWriter,

@Override
public boolean shouldInclude(String path) {
return definition.getPathFilter().filter(path) != PathFilter.Result.EXCLUDE;
return getFilterResult(path) != PathFilter.Result.EXCLUDE;
}

@Override
Expand All @@ -64,19 +64,26 @@ public boolean shouldInclude(NodeDocument doc) {
}

@Override
public void index(NodeStateEntry entry) throws IOException, CommitFailedException {
public boolean index(NodeStateEntry entry) throws IOException, CommitFailedException {
if (getFilterResult(entry.getPath()) != PathFilter.Result.INCLUDE) {
return false;
}

IndexingRule indexingRule = definition.getApplicableIndexingRule(entry.getNodeState());

if (indexingRule == null) {
return;
return false;
}

LuceneDocumentMaker maker = newDocumentMaker(indexingRule, entry.getPath());
Document doc = maker.makeDocument(entry.getNodeState());
if (doc != null) {
writeToIndex(doc, entry.getPath());
progressReporter.indexUpdate(definition.getIndexPath());
return true;
}

return false;
}

@Override
Expand All @@ -94,6 +101,10 @@ public void close() throws IOException {
indexWriter.close(System.currentTimeMillis());
}

private PathFilter.Result getFilterResult(String path) {
return definition.getPathFilter().filter(path);
}

private void writeToIndex(Document doc, String path) throws IOException {
indexWriter.updateDocument(path, doc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public interface NodeStateIndexer extends Closeable{

boolean shouldInclude(NodeDocument doc);

void index(NodeStateEntry entry) throws IOException, CommitFailedException;
boolean index(NodeStateEntry entry) throws IOException, CommitFailedException;

boolean indexesRelativeNodes();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,12 @@ public boolean shouldInclude(NodeDocument doc) {
}

@Override
public void index(NodeStateEntry entry) throws IOException, CommitFailedException {
public boolean index(NodeStateEntry entry) throws IOException, CommitFailedException {
if (p.test(entry.getPath())) {
paths.add(entry.getPath());
return true;
}
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.index.indexer.document;

import org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition;
import org.apache.jackrabbit.oak.plugins.index.lucene.binary.BinaryTextExtractor;
import org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder;
import org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter;
import org.apache.jackrabbit.oak.plugins.index.progress.IndexingProgressReporter;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.junit.Test;

import static org.apache.jackrabbit.oak.InitialContent.INITIAL_CONTENT;
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;

public class LuceneIndexerTest {
private NodeState root = INITIAL_CONTENT;

@Test
public void nodeIndexed_WithIncludedPaths() throws Exception{
IndexDefinitionBuilder idxb = new IndexDefinitionBuilder();
idxb.indexRule("nt:base").property("foo").propertyIndex();
idxb.includedPaths("/content");

NodeState defn = idxb.build();
IndexDefinition idxDefn = new IndexDefinition(root, defn, "/oak:index/testIndex");

NodeBuilder builder = root.builder();
LuceneIndexer indexer = new LuceneIndexer(idxDefn, mock(LuceneIndexWriter.class), builder,
mock(BinaryTextExtractor.class), mock(IndexingProgressReporter.class));

NodeState testNode = EMPTY_NODE.builder().setProperty("foo","bar").getNodeState();

assertTrue(indexer.index(new NodeStateEntry(testNode, "/content/x")));
assertFalse(indexer.index(new NodeStateEntry(testNode, "/x")));
assertFalse(indexer.index(new NodeStateEntry(testNode, "/")));
}

}

0 comments on commit a96c2ba

Please sign in to comment.