Author: alexparvulescu Date: Fri Aug 30 15:54:05 2013 New Revision: 1518999
URL: http://svn.apache.org/r1518999 Log: OAK-984 Add exclude property list to the Lucene index definition Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneIndexHelper.java jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneInitializerHelper.java Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java?rev=1518999&r1=1518998&r2=1518999&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java (original) +++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java Fri Aug 30 15:54:05 2013 @@ -36,6 +36,11 @@ public interface LuceneIndexConstants { */ String INCLUDE_PROPERTY_TYPES = "includePropertyTypes"; + /** + * exclude certain properties by name + */ + String EXCLUDE_PROPERTY_NAMES = "excludePropertyNames"; + String PERSISTENCE_NAME = "persistence"; String PERSISTENCE_OAK = "repository"; Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java?rev=1518999&r1=1518998&r2=1518999&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java (original) +++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java Fri Aug 30 15:54:05 2013 @@ -180,7 +180,8 @@ public class LuceneIndexEditor implement for (PropertyState property : state.getProperties()) { String pname = property.getName(); if (isVisible(pname) - && (context.getPropertyTypes() & (1 << property.getType().tag())) != 0) { + && (context.getPropertyTypes() & (1 << property.getType() + .tag())) != 0 && context.includeProperty(pname)) { if (Type.BINARY.tag() == property.getType().tag()) { addBinaryValue(document, property, state); } else { Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java?rev=1518999&r1=1518998&r2=1518999&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java (original) +++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java Fri Aug 30 15:54:05 2013 @@ -17,6 +17,7 @@ package org.apache.jackrabbit.oak.plugins.index.lucene; import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.getString; +import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.EXCLUDE_PROPERTY_NAMES; import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.INCLUDE_PROPERTY_TYPES; import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.INDEX_DATA_CHILD_NAME; import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.PERSISTENCE_PATH; @@ -25,6 +26,7 @@ import static org.apache.lucene.store.No import java.io.File; import java.io.IOException; +import java.util.Set; import javax.jcr.PropertyType; @@ -42,6 +44,8 @@ import org.apache.tika.parser.Parser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.collect.ImmutableSet; + public class LuceneIndexEditorContext { private static final Logger log = LoggerFactory @@ -95,16 +99,18 @@ public class LuceneIndexEditorContext { private final int propertyTypes; + private final Set<String> excludes; + private long indexedNodes; LuceneIndexEditorContext(NodeBuilder definition, Analyzer analyzer) { this.definition = definition; this.config = getIndexWriterConfig(analyzer); - PropertyState ps = definition.getProperty(INCLUDE_PROPERTY_TYPES); - if (ps != null) { + PropertyState pst = definition.getProperty(INCLUDE_PROPERTY_TYPES); + if (pst != null) { int types = 0; - for (String inc : ps.getValue(Type.STRINGS)) { + for (String inc : pst.getValue(Type.STRINGS)) { try { types |= 1 << PropertyType.valueFromName(inc); } catch (IllegalArgumentException e) { @@ -115,6 +121,12 @@ public class LuceneIndexEditorContext { } else { this.propertyTypes = -1; } + PropertyState pse = definition.getProperty(EXCLUDE_PROPERTY_NAMES); + if (pse != null) { + excludes = ImmutableSet.copyOf(pse.getValue(Type.STRINGS)); + } else { + excludes = ImmutableSet.of(); + } this.indexedNodes = 0; } @@ -122,6 +134,10 @@ public class LuceneIndexEditorContext { return propertyTypes; } + boolean includeProperty(String name) { + return !excludes.contains(name); + } + Parser getParser() { return parser; } Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneIndexHelper.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneIndexHelper.java?rev=1518999&r1=1518998&r2=1518999&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneIndexHelper.java (original) +++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneIndexHelper.java Fri Aug 30 15:54:05 2013 @@ -18,15 +18,18 @@ package org.apache.jackrabbit.oak.plugin import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE; import static org.apache.jackrabbit.oak.api.Type.NAME; +import static org.apache.jackrabbit.oak.api.Type.STRINGS; import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.ASYNC_PROPERTY_NAME; 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.lucene.LuceneIndexConstants.INCLUDE_PROPERTY_TYPES; +import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.EXCLUDE_PROPERTY_NAMES; import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.PERSISTENCE_FILE; import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.PERSISTENCE_NAME; import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.PERSISTENCE_PATH; import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.TYPE_LUCENE; +import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty; import java.util.Set; @@ -34,8 +37,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.jcr.PropertyType; -import org.apache.jackrabbit.oak.api.Type; -import org.apache.jackrabbit.oak.plugins.memory.PropertyStates; import org.apache.jackrabbit.oak.spi.state.NodeBuilder; import com.google.common.collect.ImmutableSet; @@ -51,12 +52,13 @@ public class LuceneIndexHelper { public static NodeBuilder newLuceneIndexDefinition( @Nonnull NodeBuilder index, @Nonnull String name, @Nullable Set<String> propertyTypes) { - return newLuceneIndexDefinition(index, name, propertyTypes, null); + return newLuceneIndexDefinition(index, name, propertyTypes, null, null); } public static NodeBuilder newLuceneIndexDefinition( @Nonnull NodeBuilder index, @Nonnull String name, - @Nullable Set<String> propertyTypes, String async) { + @Nullable Set<String> propertyTypes, + @Nullable Set<String> excludes, @Nullable String async) { if (index.hasChildNode(name)) { return index.child(name); } @@ -68,8 +70,12 @@ public class LuceneIndexHelper { index.setProperty(ASYNC_PROPERTY_NAME, async); } if (propertyTypes != null && !propertyTypes.isEmpty()) { - index.setProperty(PropertyStates.createProperty( - INCLUDE_PROPERTY_TYPES, propertyTypes, Type.STRINGS)); + index.setProperty(createProperty(INCLUDE_PROPERTY_TYPES, + propertyTypes, STRINGS)); + } + if (excludes != null && !excludes.isEmpty()) { + index.setProperty(createProperty(EXCLUDE_PROPERTY_NAMES, excludes, + STRINGS)); } return index; } @@ -77,14 +83,15 @@ public class LuceneIndexHelper { public static NodeBuilder newLuceneFileIndexDefinition( @Nonnull NodeBuilder index, @Nonnull String name, @Nullable Set<String> propertyTypes, @Nonnull String path) { - return newLuceneFileIndexDefinition( - index, name, propertyTypes, path, null); + return newLuceneFileIndexDefinition(index, name, propertyTypes, null, + path, null); } public static NodeBuilder newLuceneFileIndexDefinition( @Nonnull NodeBuilder index, @Nonnull String name, - @Nullable Set<String> propertyTypes, @Nonnull String path, - String async) { + @Nullable Set<String> propertyTypes, + @Nullable Set<String> excludes, @Nonnull String path, + @Nullable String async) { if (index.hasChildNode(name)) { return index.child(name); } @@ -98,8 +105,12 @@ public class LuceneIndexHelper { index.setProperty(ASYNC_PROPERTY_NAME, async); } if (propertyTypes != null && !propertyTypes.isEmpty()) { - index.setProperty(PropertyStates.createProperty( - INCLUDE_PROPERTY_TYPES, propertyTypes, Type.STRINGS)); + index.setProperty(createProperty(INCLUDE_PROPERTY_TYPES, + propertyTypes, STRINGS)); + } + if (excludes != null && !excludes.isEmpty()) { + index.setProperty(createProperty(EXCLUDE_PROPERTY_NAMES, excludes, + STRINGS)); } return index; } Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneInitializerHelper.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneInitializerHelper.java?rev=1518999&r1=1518998&r2=1518999&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneInitializerHelper.java (original) +++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneInitializerHelper.java Fri Aug 30 15:54:05 2013 @@ -32,22 +32,35 @@ public class LuceneInitializerHelper imp private final Set<String> propertyTypes; + private final Set<String> excludes; + private final String filePath; private String async = null; public LuceneInitializerHelper(String name) { - this(name, LuceneIndexHelper.JR_PROPERTY_INCLUDES); + this(name, LuceneIndexHelper.JR_PROPERTY_INCLUDES, null, null); } public LuceneInitializerHelper(String name, Set<String> propertyTypes) { - this(name, propertyTypes, null); + this(name, propertyTypes, null, null); + } + + public LuceneInitializerHelper(String name, Set<String> propertyTypes, + Set<String> excludes) { + this(name, propertyTypes, excludes, null); } public LuceneInitializerHelper(String name, Set<String> propertyTypes, String filePath) { + this(name, propertyTypes, null, filePath); + } + + public LuceneInitializerHelper(String name, Set<String> propertyTypes, + Set<String> excludes, String filePath) { this.name = name; this.propertyTypes = propertyTypes; + this.excludes = excludes; this.filePath = filePath; } @@ -67,10 +80,10 @@ public class LuceneInitializerHelper imp if (filePath == null) { newLuceneIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), - name, propertyTypes, async); + name, propertyTypes, excludes, async); } else { newLuceneFileIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), - name, propertyTypes, filePath, async); + name, propertyTypes, excludes, filePath, async); } return builder.getNodeState(); }
