You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by al...@apache.org on 2012/10/08 16:08:41 UTC
svn commit: r1395573 - in /jackrabbit/oak/trunk/oak-core/src:
main/java/org/apache/jackrabbit/oak/plugins/index/
main/java/org/apache/jackrabbit/oak/plugins/index/lucene/
main/java/org/apache/jackrabbit/oak/plugins/index/old/
test/java/org/apache/jackr...
Author: alexparvulescu
Date: Mon Oct 8 14:08:40 2012
New Revision: 1395573
URL: http://svn.apache.org/viewvc?rev=1395573&view=rev
Log:
OAK-368 Unify all index definitions under oak:index
- refactored IndexDefinition class to drop properties and rely on wrapped NodeState
- cosmetic refactorings
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexConstants.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexDefinition.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexDefinitionImpl.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneEditor.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneHook.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProvider.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneReindexHook.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyIndexConstants.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyIndexer.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexQueryTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/old/QueryTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexConstants.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexConstants.java?rev=1395573&r1=1395572&r2=1395573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexConstants.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexConstants.java Mon Oct 8 14:08:40 2012
@@ -18,6 +18,16 @@ package org.apache.jackrabbit.oak.plugin
public interface IndexConstants {
+ String INDEX_DEFINITIONS_NAME = "oak:index";
+
String TYPE_PROPERTY_NAME = "type";
+ String TYPE_UNKNOWN = "unknown";
+
+ String REINDEX_PROPERTY_NAME = "reindex";
+
+ String INDEX_DATA_CHILD_NAME = ":data";
+
+ String DEFAULT_INDEX_HOME = "/";
+
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexDefinition.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexDefinition.java?rev=1395573&r1=1395572&r2=1395573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexDefinition.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexDefinition.java Mon Oct 8 14:08:40 2012
@@ -16,20 +16,16 @@
*/
package org.apache.jackrabbit.oak.plugins.index;
-import java.util.Map;
-
import javax.annotation.Nonnull;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
/**
* Defines an index definition
*
*/
public interface IndexDefinition {
- String UNIQUE_PROPERTY_NAME = "unique";
-
- String INDEX_DATA_CHILD_NAME = ":data";
-
/**
* Get the unique index name. This is also the name of the index node.
*
@@ -39,28 +35,26 @@ public interface IndexDefinition {
String getName();
/**
- * @return the index type
+ * @return the index path, including the name as the last segment
*/
@Nonnull
- String getType();
+ String getPath();
/**
- * @return the index path, including the name as the last segment
+ * @return the index type
*/
@Nonnull
- String getPath();
+ String getType();
/**
- * Whether each value may only appear once in the index.
- *
- * @return true if unique
+ * @return flag marking if reindexing is required on this index
*/
- boolean isUnique();
+ boolean isReindex();
/**
- * @return the index properties
+ * @return the state that this definition is built on
*/
@Nonnull
- Map<String, String> getProperties();
+ NodeState getState();
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexDefinitionImpl.java?rev=1395573&r1=1395572&r2=1395573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexDefinitionImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexDefinitionImpl.java Mon Oct 8 14:08:40 2012
@@ -16,33 +16,23 @@
*/
package org.apache.jackrabbit.oak.plugins.index;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
-public class IndexDefinitionImpl implements IndexDefinition {
+public class IndexDefinitionImpl implements IndexDefinition, IndexConstants {
private final String name;
private final String type;
private final String path;
- private final boolean unique;
- private final Map<String, String> properties;
-
- public IndexDefinitionImpl(String name, String type, String path) {
- this(name, type, path, false, Collections.<String, String> emptyMap());
- }
+ private final NodeState state;
public IndexDefinitionImpl(String name, String type, String path,
- boolean unique, Map<String, String> properties) {
+ NodeState state) {
this.name = name;
this.type = type;
this.path = path;
- this.unique = unique;
- if (properties != null) {
- this.properties = properties;
- } else {
- this.properties = new HashMap<String, String>();
- }
+ this.state = state;
}
@Override
@@ -61,30 +51,28 @@ public class IndexDefinitionImpl impleme
}
@Override
- public boolean isUnique() {
- return unique;
+ public boolean isReindex() {
+ PropertyState ps = state.getProperty(REINDEX_PROPERTY_NAME);
+ return ps != null && ps.getValue(Type.BOOLEAN);
}
@Override
- public Map<String, String> getProperties() {
- return properties;
+ public NodeState getState() {
+ return state;
}
@Override
public String toString() {
return "IndexDefinitionImpl [name=" + name + ", type=" + type
- + ", path=" + path + ", unique=" + unique + ", properties="
- + properties + "]";
+ + ", path=" + path + ", reindex=" + isReindex() + ", state="
+ + state + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + ((path == null) ? 0 : path.hashCode());
- result = prime * result + ((type == null) ? 0 : type.hashCode());
- result = prime * result + (unique ? 1231 : 1237);
+ result = prime * result + ((state == null) ? 0 : state.hashCode());
return result;
}
@@ -97,22 +85,10 @@ public class IndexDefinitionImpl impleme
if (getClass() != obj.getClass())
return false;
IndexDefinitionImpl other = (IndexDefinitionImpl) obj;
- if (name == null) {
- if (other.name != null)
- return false;
- } else if (!name.equals(other.name))
- return false;
- if (path == null) {
- if (other.path != null)
+ if (state == null) {
+ if (other.state != null)
return false;
- } else if (!path.equals(other.path))
- return false;
- if (type == null) {
- if (other.type != null)
- return false;
- } else if (!type.equals(other.type))
- return false;
- if (unique != other.unique)
+ } else if (!state.equals(other.state))
return false;
return true;
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java?rev=1395573&r1=1395572&r2=1395573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java Mon Oct 8 14:08:40 2012
@@ -16,107 +16,39 @@
*/
package org.apache.jackrabbit.oak.plugins.index;
+import static org.apache.jackrabbit.oak.api.Type.STRING;
+import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
+
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.commons.PathUtils;
-import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants;
import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
-import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
-import static org.apache.jackrabbit.oak.api.Type.BOOLEAN;
-import static org.apache.jackrabbit.oak.api.Type.STRING;
-import static org.apache.jackrabbit.oak.plugins.index.IndexDefinition.INDEX_DATA_CHILD_NAME;
-import static org.apache.jackrabbit.oak.plugins.index.IndexDefinition.UNIQUE_PROPERTY_NAME;
-
public class IndexUtils implements IndexConstants {
/**
- * switch to "oak:index" as soon as it is possible
- */
- public static final String DEFAULT_INDEX_HOME = "/oak:index";
-
- private static final String TYPE_UNKNOWN = "unknown";
-
- /**
- * Builds an {@link IndexDefinition} out of a {@link ChildNodeEntry}
+ * Builds a list of the existing index definitions.
*
- */
- public static IndexDefinition getDefinition(String path, ChildNodeEntry def) {
- String name = def.getName();
- NodeState ns = def.getNodeState();
- PropertyState typeProp = ns.getProperty(TYPE_PROPERTY_NAME);
- String type = TYPE_UNKNOWN;
- if (typeProp != null && !typeProp.isArray()) {
- type = typeProp.getValue(STRING);
- }
-
- boolean unique = false;
- PropertyState uniqueProp = ns.getProperty(UNIQUE_PROPERTY_NAME);
- if (uniqueProp != null && !uniqueProp.isArray()) {
- unique = uniqueProp.getValue(BOOLEAN);
- }
-
- Map<String, String> props = new HashMap<String, String>();
- for (PropertyState ps : ns.getProperties()) {
- if (ps != null && !ps.isArray()) {
- String v = ps.getValue(STRING);
- props.put(ps.getName(), v);
- }
- }
- // TODO hack to circumvent observation events
- if (ns.hasChildNode(INDEX_DATA_CHILD_NAME)) {
- PropertyState ps = ns.getChildNode(INDEX_DATA_CHILD_NAME)
- .getProperty(LuceneIndexConstants.INDEX_UPDATE);
- if (ps != null) {
- props.put(LuceneIndexConstants.INDEX_UPDATE, ps.getValue(STRING));
- }
- }
-
- return new IndexDefinitionImpl(name, type,
- PathUtils.concat(path, name), unique, props);
- }
-
- /**
- * @return the 'destination' node if the path exists, null if otherwise
- */
- public static NodeState getNode(NodeState nodeState, String destination) {
- NodeState retval = nodeState;
- Iterator<String> pathIterator = PathUtils.elements(destination)
- .iterator();
- while (pathIterator.hasNext()) {
- String path = pathIterator.next();
- if (retval.hasChildNode(path)) {
- retval = retval.getChildNode(path);
- } else {
- return null;
- }
- }
- return retval;
- }
-
- /**
- * Builds a list of the existing index definitions from the repository
+ * Checks only children of the provided state for an index definitions
+ * container node, aka a node named {@link INDEX_DEFINITIONS_NAME}
*
+ * @return
*/
- public static List<IndexDefinition> buildIndexDefinitions(
- NodeState nodeState, String indexConfigPath, String typeFilter) {
- NodeState definitions = getNode(nodeState, indexConfigPath);
+ public static List<IndexDefinition> buildIndexDefinitions(NodeState state,
+ String indexConfigPath, String typeFilter) {
+ NodeState definitions = state.getChildNode(INDEX_DEFINITIONS_NAME);
if (definitions == null) {
return Collections.emptyList();
}
+ indexConfigPath = concat(indexConfigPath, INDEX_DEFINITIONS_NAME);
List<IndexDefinition> defs = new ArrayList<IndexDefinition>();
for (ChildNodeEntry c : definitions.getChildNodeEntries()) {
- IndexDefinition def = getDefinition(indexConfigPath, c);
- if (def == null
- || (typeFilter != null && !typeFilter.equals(def.getType()))) {
+ IndexDefinition def = getDefinition(indexConfigPath, c, typeFilter);
+ if (def == null) {
continue;
}
defs.add(def);
@@ -124,12 +56,23 @@ public class IndexUtils implements Index
return defs;
}
- public static NodeBuilder getChildBuilder(NodeState state, String path) {
- NodeBuilder builder = state.builder();
- for (String p : PathUtils.elements(path)) {
- builder = builder.child(p);
+ /**
+ * Builds an {@link IndexDefinition} out of a {@link ChildNodeEntry}
+ *
+ */
+ private static IndexDefinition getDefinition(String path,
+ ChildNodeEntry def, String typeFilter) {
+ String name = def.getName();
+ NodeState ns = def.getNodeState();
+ PropertyState typeProp = ns.getProperty(TYPE_PROPERTY_NAME);
+ String type = TYPE_UNKNOWN;
+ if (typeProp != null && !typeProp.isArray()) {
+ type = typeProp.getValue(STRING);
+ }
+ if (typeFilter != null && !typeFilter.equals(type)) {
+ return null;
}
- return builder;
+ return new IndexDefinitionImpl(name, type, concat(path, name), ns);
}
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneEditor.java?rev=1395573&r1=1395572&r2=1395573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneEditor.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneEditor.java Mon Oct 8 14:08:40 2012
@@ -16,6 +16,12 @@
*/
package org.apache.jackrabbit.oak.plugins.index.lucene;
+import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
+import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
+import static org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newPathField;
+import static org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newPropertyField;
+import static org.apache.jackrabbit.oak.plugins.index.lucene.TermFactory.newPathTerm;
+
import java.io.IOException;
import javax.jcr.PropertyType;
@@ -41,13 +47,6 @@ import org.apache.lucene.util.Version;
import org.apache.tika.Tika;
import org.apache.tika.exception.TikaException;
-import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
-import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
-import static org.apache.jackrabbit.oak.plugins.index.IndexDefinition.INDEX_DATA_CHILD_NAME;
-import static org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newPathField;
-import static org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newPropertyField;
-import static org.apache.jackrabbit.oak.plugins.index.lucene.TermFactory.newPathTerm;
-
/**
* This class updates a Lucene index when node content is changed.
*/
@@ -98,7 +97,7 @@ class LuceneEditor implements CommitHook
diff.postProcess(after);
} finally {
writer.close();
- builder.setProperty(INDEX_UPDATE, System.currentTimeMillis());
+ builder.setProperty(REINDEX_PROPERTY_NAME, false);
}
return rootBuilder.getNodeState();
} catch (IOException e) {
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneHook.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneHook.java?rev=1395573&r1=1395572&r2=1395573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneHook.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneHook.java Mon Oct 8 14:08:40 2012
@@ -16,12 +16,13 @@
*/
package org.apache.jackrabbit.oak.plugins.index.lucene;
+import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.buildIndexDefinitions;
+
import java.util.ArrayList;
import java.util.List;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.plugins.index.IndexDefinition;
-import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
import org.apache.jackrabbit.oak.spi.commit.CommitHook;
import org.apache.jackrabbit.oak.spi.commit.CompositeHook;
import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -34,19 +35,12 @@ public class LuceneHook implements Commi
this.indexConfigPath = indexConfigPath;
}
- /**
- * TODO test only
- */
- public LuceneHook() {
- this(IndexUtils.DEFAULT_INDEX_HOME);
- }
-
@Override
public NodeState processCommit(NodeState before, NodeState after)
throws CommitFailedException {
List<CommitHook> hooks = new ArrayList<CommitHook>();
- List<IndexDefinition> indexDefinitions =
- IndexUtils.buildIndexDefinitions(after, indexConfigPath, TYPE);
+ List<IndexDefinition> indexDefinitions = buildIndexDefinitions(after,
+ indexConfigPath, TYPE_LUCENE);
for (IndexDefinition def : indexDefinitions) {
hooks.add(new LuceneEditor(def));
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java?rev=1395573&r1=1395572&r2=1395573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java Mon Oct 8 14:08:40 2012
@@ -63,7 +63,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
-import static org.apache.jackrabbit.oak.plugins.index.IndexDefinition.INDEX_DATA_CHILD_NAME;
import static org.apache.jackrabbit.oak.plugins.index.lucene.FieldNames.PATH;
import static org.apache.jackrabbit.oak.plugins.index.lucene.FieldNames.PATH_SELECTOR;
import static org.apache.jackrabbit.oak.plugins.index.lucene.TermFactory.newPathTerm;
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java?rev=1395573&r1=1395572&r2=1395573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java Mon Oct 8 14:08:40 2012
@@ -16,12 +16,12 @@
*/
package org.apache.jackrabbit.oak.plugins.index.lucene;
-public interface LuceneIndexConstants {
+import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
- String TYPE = "lucene";
+public interface LuceneIndexConstants extends IndexConstants {
- String DEFAULT_INDEX_NAME = "default-lucene";
+ String TYPE_LUCENE = "lucene";
- String INDEX_UPDATE = "indexUpdate";
+ String DEFAULT_INDEX_NAME = "default-lucene";
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProvider.java?rev=1395573&r1=1395572&r2=1395573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProvider.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProvider.java Mon Oct 8 14:08:40 2012
@@ -16,6 +16,8 @@
*/
package org.apache.jackrabbit.oak.plugins.index.lucene;
+import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.buildIndexDefinitions;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -24,7 +26,6 @@ import javax.annotation.Nonnull;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.plugins.index.IndexDefinition;
-import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
import org.apache.jackrabbit.oak.spi.query.QueryIndex;
import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -53,8 +54,8 @@ public class LuceneIndexProvider impleme
return Collections.<QueryIndex> emptyList();
}
List<QueryIndex> tempIndexes = new ArrayList<QueryIndex>();
- for (IndexDefinition child : IndexUtils.buildIndexDefinitions(
- nodeState, indexPath, TYPE)) {
+ for (IndexDefinition child : buildIndexDefinitions(nodeState,
+ indexPath, TYPE_LUCENE)) {
LOG.debug("found a lucene index definition {}", child);
tempIndexes.add(new LuceneIndex(child));
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneReindexHook.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneReindexHook.java?rev=1395573&r1=1395572&r2=1395573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneReindexHook.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneReindexHook.java Mon Oct 8 14:08:40 2012
@@ -16,12 +16,13 @@
*/
package org.apache.jackrabbit.oak.plugins.index.lucene;
+import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.buildIndexDefinitions;
+
import java.util.ArrayList;
import java.util.List;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.plugins.index.IndexDefinition;
-import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeState;
import org.apache.jackrabbit.oak.spi.commit.CommitHook;
import org.apache.jackrabbit.oak.spi.commit.CompositeHook;
@@ -34,12 +35,7 @@ import org.slf4j.LoggerFactory;
* content.
*
* Currently it triggers a full reindex on any detected index definition change
- * (excepting the properties) OR on removing the
- * {@link LuceneIndexConstants#INDEX_UPDATE} property
- *
- * Warning: This hook has to be placed before the updater {@link LuceneHook},
- * otherwise it is going to miss the {@link LuceneIndexConstants#INDEX_UPDATE}
- * change to null
+ * OR on the {@link IndexDefinition#isReindex()} flag
*
*/
public class LuceneReindexHook implements CommitHook, LuceneIndexConstants {
@@ -53,21 +49,14 @@ public class LuceneReindexHook implement
this.indexConfigPath = indexConfigPath;
}
- /**
- * TODO test only
- */
- public LuceneReindexHook() {
- this(IndexUtils.DEFAULT_INDEX_HOME);
- }
-
@Override
public NodeState processCommit(NodeState before, NodeState after)
throws CommitFailedException {
- List<IndexDefinition> defsBefore = IndexUtils.buildIndexDefinitions(
- before, indexConfigPath, TYPE);
- List<IndexDefinition> defsAfter = IndexUtils.buildIndexDefinitions(
- after, indexConfigPath, TYPE);
+ List<IndexDefinition> defsBefore = buildIndexDefinitions(before,
+ indexConfigPath, TYPE_LUCENE);
+ List<IndexDefinition> defsAfter = buildIndexDefinitions(after,
+ indexConfigPath, TYPE_LUCENE);
// TODO add a more fine-grained change verifier
List<IndexDefinition> defsChanged = new ArrayList<IndexDefinition>();
@@ -75,8 +64,8 @@ public class LuceneReindexHook implement
if (!defsBefore.contains(def)) {
defsChanged.add(def);
}
- // verify initial state or forced reindex
- if (def.getProperties().get(INDEX_UPDATE) == null) {
+ // verify reindex flag
+ if (def.isReindex()) {
defsChanged.add(def);
}
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyIndexConstants.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyIndexConstants.java?rev=1395573&r1=1395572&r2=1395573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyIndexConstants.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyIndexConstants.java Mon Oct 8 14:08:40 2012
@@ -26,7 +26,7 @@ public interface PropertyIndexConstants
* The root node of the index definition (configuration) nodes.
*/
// TODO OAK-178 discuss where to store index config data
- String INDEX_CONFIG_PATH = IndexUtils.DEFAULT_INDEX_HOME + "/indexes";
+ String INDEX_CONFIG_PATH = IndexUtils.DEFAULT_INDEX_HOME + IndexUtils.INDEX_DEFINITIONS_NAME + "/indexes";
// "/jcr:system/indexes";
/**
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyIndexer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyIndexer.java?rev=1395573&r1=1395572&r2=1395573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyIndexer.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyIndexer.java Mon Oct 8 14:08:40 2012
@@ -16,6 +16,8 @@
*/
package org.apache.jackrabbit.oak.plugins.index.old;
+import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
+
import java.util.ArrayList;
import java.util.List;
@@ -48,35 +50,40 @@ public class PropertyIndexer implements
return after;
}
- @Override @Nonnull
+ @Override
+ @Nonnull
public List<? extends QueryIndex> getQueryIndexes(NodeState nodeState) {
List<QueryIndex> queryIndexList = new ArrayList<QueryIndex>();
- NodeBuilder rootBuilder = IndexUtils.getChildBuilder(nodeState,
- indexConfigPath);
List<IndexDefinition> indexDefinitions = IndexUtils
.buildIndexDefinitions(nodeState, indexConfigPath,
INDEX_TYPE_PROPERTY);
for (IndexDefinition def : indexDefinitions) {
- NodeBuilder builder = rootBuilder.child(def.getName());
- // create the global :data node
- builder.child(INDEX_CONTENT);
+ NodeBuilder builder = childBuilder(nodeState, def.getPath());
for (String k : builder.getChildNodeNames()) {
PropertyIndex prop = PropertyIndex.fromNodeName(indexer, k);
if (prop != null) {
// create the :data node
- builder.child(prop.getIndexNodeName())
- .child(INDEX_CONTENT);
+ builder.child(prop.getIndexNodeName()).child(INDEX_CONTENT);
queryIndexList.add(new PropertyContentIndex(prop));
}
PrefixIndex pref = PrefixIndex.fromNodeName(indexer, k);
if (pref != null) {
// create the :data node
- builder.child(pref.getIndexNodeName())
- .child(INDEX_CONTENT);
+ builder.child(pref.getIndexNodeName()).child(INDEX_CONTENT);
queryIndexList.add(new PrefixContentIndex(pref));
}
}
+ // create the global :data node
+ builder.child(INDEX_CONTENT);
}
return queryIndexList;
}
+
+ private static NodeBuilder childBuilder(NodeState state, String path) {
+ NodeBuilder builder = state.builder();
+ for (String p : elements(path)) {
+ builder = builder.child(p);
+ }
+ return builder;
+ }
}
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexQueryTest.java?rev=1395573&r1=1395572&r2=1395573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexQueryTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexQueryTest.java Mon Oct 8 14:08:40 2012
@@ -37,7 +37,7 @@ public class LuceneIndexQueryTest extend
@Override
protected void createTestIndexNode() throws Exception {
Tree index = root.getTree("/");
- createTestIndexNode(index, TYPE);
+ createTestIndexNode(index, TYPE_LUCENE);
root.commit();
}
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java?rev=1395573&r1=1395572&r2=1395573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java Mon Oct 8 14:08:40 2012
@@ -38,21 +38,23 @@ import org.junit.Test;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
-import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.DEFAULT_INDEX_HOME;
public class LuceneIndexTest implements LuceneIndexConstants {
@Test
public void testLucene() throws Exception {
+ KernelNodeStore store = new KernelNodeStore(new MicroKernelImpl());
+
IndexDefinition testID = new IndexDefinitionImpl(DEFAULT_INDEX_NAME,
- TYPE, DEFAULT_INDEX_HOME, false, null);
+ TYPE_LUCENE, DEFAULT_INDEX_HOME + INDEX_DEFINITIONS_NAME + "/"
+ + DEFAULT_INDEX_NAME, store.getRoot());
- KernelNodeStore store = new KernelNodeStore(new MicroKernelImpl());
store.setHook(new LuceneEditor(testID));
Root root = new RootImpl(store, null, new Subject(),
- new AccessControlProviderImpl(), new CompositeQueryIndexProvider());
- Tree tree = root.getTree("/");
+ new AccessControlProviderImpl(),
+ new CompositeQueryIndexProvider());
+ Tree tree = root.getTree("/");
tree.setProperty("foo", "bar");
root.commit();
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/old/QueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/old/QueryTest.java?rev=1395573&r1=1395572&r2=1395573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/old/QueryTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/old/QueryTest.java Mon Oct 8 14:08:40 2012
@@ -35,7 +35,7 @@ public class QueryTest extends AbstractQ
// the property and prefix index currently require the index wrapper
IndexWrapper mk = new IndexWrapper(new MicroKernelImpl(),
- PathUtils.concat(TEST_INDEX_HOME, TEST_INDEX_NAME));
+ TEST_INDEX_HOME + INDEX_DEFINITIONS_NAME + "/indexes");
Indexer indexer = mk.getIndexer();
// MicroKernel mk = new MicroKernelImpl();
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java?rev=1395573&r1=1395572&r2=1395573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java Mon Oct 8 14:08:40 2012
@@ -16,7 +16,6 @@
*/
package org.apache.jackrabbit.oak.query;
-import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.DEFAULT_INDEX_HOME;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -98,10 +97,12 @@ public abstract class AbstractQueryTest
indexDef = indexDef.addChild(p);
}
}
- indexDef = indexDef.addChild(TEST_INDEX_NAME);
+ indexDef = indexDef.addChild(INDEX_DEFINITIONS_NAME).addChild(
+ TEST_INDEX_NAME);
indexDef.setProperty(JcrConstants.JCR_PRIMARYTYPE,
INDEX_DEFINITION_NODE_TYPE);
indexDef.setProperty(TYPE_PROPERTY_NAME, type);
+ indexDef.setProperty(REINDEX_PROPERTY_NAME, true);
return indexDef;
}