jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1375930 [1/2] - in /jackrabbit/oak/trunk: oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/ oak-core/src/main/java/org/apache/jackrabbit/mk/index/ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/main/j...
Date Wed, 22 Aug 2012 08:04:52 GMT
Author: alexparvulescu
Date: Wed Aug 22 08:04:51 2012
New Revision: 1375930

URL: http://svn.apache.org/viewvc?rev=1375930&view=rev
Log:
OAK-269 Query: IndexManager to manage existing indexes

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/BTree.java
      - copied, changed from r1375422, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTree.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/BTreeLeaf.java
      - copied, changed from r1375422, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreeLeaf.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/BTreeNode.java
      - copied, changed from r1375422, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreeNode.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/BTreePage.java
      - copied, changed from r1375422, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreePage.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/Cursor.java
      - copied, changed from r1375422, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Cursor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/Indexer.java   (contents, props changed)
      - copied, changed from r1375547, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PIndex.java   (with props)
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PrefixIndex.java
      - copied, changed from r1375422, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/PrefixIndex.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndex.java
      - copied, changed from r1375422, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/PropertyIndex.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndexFactory.java   (with props)
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexFactory.java   (with props)
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Index.java   (with props)
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexDefinition.java   (with props)
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexDefinitionImpl.java   (with props)
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexFactory.java   (with props)
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexManager.java   (with props)
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexManagerImpl.java   (with props)
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexUtils.java   (with props)
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/query/
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/query/IndexManagerTest.java   (with props)
Removed:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTree.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreeLeaf.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreeNode.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreePage.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Cursor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Index.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/PrefixIndex.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/PropertyIndex.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexInfo.java
Modified:
    jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/IndexManager.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexUtils.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/PrefixContentIndex.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/PropertyContentIndex.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PropertyIndexTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/IndexWrapperTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/AbstractLuceneQueryTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditorTest.java
    jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryTest.txt

Modified: jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/IndexManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/IndexManager.java?rev=1375930&r1=1375929&r2=1375930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/IndexManager.java (original)
+++ jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/IndexManager.java Wed Aug 22 08:04:51 2012
@@ -19,8 +19,9 @@ package org.apache.jackrabbit.oak.perfor
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
-import org.apache.jackrabbit.mk.index.Indexer;
+
 import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.plugins.index.Indexer;
 
 /**
  * A utility class to manage indexes in Oak.

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java?rev=1375930&r1=1375929&r2=1375930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java Wed Aug 22 08:04:51 2012
@@ -28,6 +28,9 @@ import org.apache.jackrabbit.mk.api.Micr
 import org.apache.jackrabbit.mk.json.JsopReader;
 import org.apache.jackrabbit.mk.json.JsopStream;
 import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.plugins.index.Indexer;
+import org.apache.jackrabbit.oak.plugins.index.PrefixIndex;
+import org.apache.jackrabbit.oak.plugins.index.PropertyIndex;
 import org.apache.jackrabbit.mk.wrapper.MicroKernelWrapper;
 import org.apache.jackrabbit.mk.wrapper.MicroKernelWrapperBase;
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java?rev=1375930&r1=1375929&r2=1375930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java Wed Aug 22 08:04:51 2012
@@ -26,7 +26,7 @@ import javax.security.auth.login.LoginEx
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.core.MicroKernelImpl;
-import org.apache.jackrabbit.mk.index.Indexer;
+import org.apache.jackrabbit.oak.plugins.index.Indexer;
 import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.kernel.KernelNodeStore;

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/BTree.java (from r1375422, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTree.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/BTree.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/BTree.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTree.java&r1=1375422&r2=1375930&rev=1375930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTree.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/BTree.java Wed Aug 22 08:04:51 2012
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mk.index;
+package org.apache.jackrabbit.oak.plugins.index;
 
 import org.apache.jackrabbit.mk.json.JsopBuilder;
 import org.apache.jackrabbit.oak.commons.PathUtils;
@@ -264,7 +264,7 @@ public class BTree {
         }
     }
 
-    String getName() {
+    public String getName() {
         return name;
     }
 

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/BTreeLeaf.java (from r1375422, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreeLeaf.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/BTreeLeaf.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/BTreeLeaf.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreeLeaf.java&r1=1375422&r2=1375930&rev=1375930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreeLeaf.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/BTreeLeaf.java Wed Aug 22 08:04:51 2012
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mk.index;
+package org.apache.jackrabbit.oak.plugins.index;
 
 import java.util.Arrays;
 
@@ -25,9 +25,9 @@ import org.apache.jackrabbit.oak.util.Ar
 /**
  * An index leaf page.
  */
-class BTreeLeaf extends BTreePage {
+public class BTreeLeaf extends BTreePage {
 
-    BTreeLeaf(BTree tree, BTreeNode parent, String name, String[] data, String[] paths) {
+    public BTreeLeaf(BTree tree, BTreeNode parent, String name, String[] data, String[] paths) {
         super(tree, parent, name, data, paths);
         verify();
     }

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/BTreeNode.java (from r1375422, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreeNode.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/BTreeNode.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/BTreeNode.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreeNode.java&r1=1375422&r2=1375930&rev=1375930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreeNode.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/BTreeNode.java Wed Aug 22 08:04:51 2012
@@ -14,9 +14,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mk.index;
+package org.apache.jackrabbit.oak.plugins.index;
 
 import java.util.Arrays;
+
 import org.apache.jackrabbit.mk.json.JsopBuilder;
 import org.apache.jackrabbit.oak.util.ArrayUtils;
 import org.apache.jackrabbit.oak.commons.PathUtils;
@@ -24,11 +25,11 @@ import org.apache.jackrabbit.oak.commons
 /**
  * An index node page.
  */
-class BTreeNode extends BTreePage {
+public class BTreeNode extends BTreePage {
 
     private String[] children;
 
-    BTreeNode(BTree tree, BTreeNode parent, String name, String[] keys, String[] values, String[] children) {
+    public BTreeNode(BTree tree, BTreeNode parent, String name, String[] keys, String[] values, String[] children) {
         super(tree, parent, name, keys, values);
         this.children = children;
         verify();

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/BTreePage.java (from r1375422, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreePage.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/BTreePage.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/BTreePage.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreePage.java&r1=1375422&r2=1375930&rev=1375930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreePage.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/BTreePage.java Wed Aug 22 08:04:51 2012
@@ -14,14 +14,14 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mk.index;
+package org.apache.jackrabbit.oak.plugins.index;
 
 import org.apache.jackrabbit.oak.commons.PathUtils;
 
 /**
  * An index page.
  */
-abstract class BTreePage {
+abstract public class BTreePage {
 
     protected final BTree tree;
     protected BTreeNode parent;
@@ -65,7 +65,7 @@ abstract class BTreePage {
         return parent == null ? "" : parent.getPath();
     }
 
-    String getPath() {
+    public String getPath() {
         return PathUtils.concat(getParentPath(), name);
     }
 

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/Cursor.java (from r1375422, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Cursor.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/Cursor.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/Cursor.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Cursor.java&r1=1375422&r2=1375930&rev=1375930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Cursor.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/Cursor.java Wed Aug 22 08:04:51 2012
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mk.index;
+package org.apache.jackrabbit.oak.plugins.index;
 
 import java.util.Iterator;
 

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/Indexer.java (from r1375547, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/Indexer.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/Indexer.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java&r1=1375547&r2=1375930&rev=1375930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/Indexer.java Wed Aug 22 08:04:51 2012
@@ -14,11 +14,18 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mk.index;
+package org.apache.jackrabbit.oak.plugins.index;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map.Entry;
 
 import org.apache.jackrabbit.mk.ExceptionFactory;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
+import org.apache.jackrabbit.mk.index.IndexWrapper;
 import org.apache.jackrabbit.mk.json.JsopBuilder;
 import org.apache.jackrabbit.mk.json.JsopReader;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
@@ -26,15 +33,12 @@ import org.apache.jackrabbit.mk.simple.N
 import org.apache.jackrabbit.mk.simple.NodeMap;
 import org.apache.jackrabbit.mk.util.SimpleLRUCache;
 import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.query.index.PrefixContentIndex;
 import org.apache.jackrabbit.oak.query.index.PropertyContentIndex;
 import org.apache.jackrabbit.oak.spi.QueryIndex;
 import org.apache.jackrabbit.oak.spi.QueryIndexProvider;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map.Entry;
+import org.apache.jackrabbit.oak.spi.query.Index;
+import org.apache.jackrabbit.oak.spi.query.IndexUtils;
 
 /**
  * A index mechanism. An index is bound to a certain repository, and supports
@@ -46,7 +50,8 @@ public class Indexer implements QueryInd
      * The root node of the index definition (configuration) nodes.
      */
     // TODO OAK-178 discuss where to store index config data
-    public static final String INDEX_CONFIG_PATH = "/jcr:system/indexes";
+    public static final String INDEX_CONFIG_PATH = IndexUtils.DEFAULT_INDEX_HOME + "/indexes";
+            //"/jcr:system/indexes";
 
     /**
      * For each index, the index content is stored relative to the index
@@ -58,18 +63,18 @@ public class Indexer implements QueryInd
     /**
      * The node name prefix of a prefix index.
      */
-    static final String TYPE_PREFIX = "prefix@";
+    public static final String TYPE_PREFIX = "prefix@";
 
     /**
      * The node name prefix of a property index.
      */
     // TODO support multi-property indexes
-    static final String TYPE_PROPERTY = "property@";
+    public static final String TYPE_PROPERTY = "property@";
 
     /**
      * Marks a unique index.
      */
-    static final String UNIQUE = "unique";
+    public static final String UNIQUE = "unique";
 
     /**
      * The maximum length of the write buffer.
@@ -92,7 +97,7 @@ public class Indexer implements QueryInd
     /**
      * An index node name to index map.
      */
-    private HashMap<String, Index> indexes = new HashMap<String, Index>();
+    private HashMap<String, PIndex> indexes = new HashMap<String, PIndex>();
 
     /**
      * A prefix to prefix index map.
@@ -104,7 +109,7 @@ public class Indexer implements QueryInd
      */
     private final HashMap<String, PropertyIndex> propertyIndexes = new HashMap<String, PropertyIndex>();
 
-    Indexer(MicroKernel mk) {
+    public Indexer(MicroKernel mk) {
         this.mk = mk;
     }
 
@@ -125,7 +130,7 @@ public class Indexer implements QueryInd
         return new Indexer(mk);
     }
 
-    String getIndexRootNode() {
+    public String getIndexRootNode() {
         return indexRootNode;
     }
 
@@ -156,13 +161,13 @@ public class Indexer implements QueryInd
                 String k = n.getChildNodeName(i);
                 PropertyIndex prop = PropertyIndex.fromNodeName(this, k);
                 if (prop != null) {
-                    indexes.put(prop.getIndexNodeName(), prop);
+                    indexes.put(prop.getDefinition().getName(), prop);
                     propertyIndexes.put(prop.getPropertyName(), prop);
                     queryIndexList = null;
                 }
                 PrefixIndex pref = PrefixIndex.fromNodeName(this, k);
                 if (pref != null) {
-                    indexes.put(pref.getIndexNodeName(), pref);
+                    indexes.put(pref.getDefinition().getName(), pref);
                     prefixIndexes.put(pref.getPrefix(), pref);
                     queryIndexList = null;
                 }
@@ -172,7 +177,7 @@ public class Indexer implements QueryInd
 
     private void removePropertyIndex(String property, boolean unique) {
         PropertyIndex index = propertyIndexes.remove(property);
-        indexes.remove(index.getIndexNodeName());
+        indexes.remove(index.getDefinition().getName());
         queryIndexList = null;
     }
 
@@ -183,7 +188,7 @@ public class Indexer implements QueryInd
         }
         PropertyIndex index = new PropertyIndex(this, property, unique);
         buildIndex(index);
-        indexes.put(index.getIndexNodeName(), index);
+        indexes.put(index.getDefinition().getName(), index);
         propertyIndexes.put(index.getPropertyName(), index);
         queryIndexList = null;
         return index;
@@ -191,7 +196,7 @@ public class Indexer implements QueryInd
 
     private void removePrefixIndex(String prefix) {
          PrefixIndex index = prefixIndexes.remove(prefix);
-         indexes.remove(index.getIndexNodeName());
+         indexes.remove(index.getDefinition().getName());
          queryIndexList = null;
     }
 
@@ -202,7 +207,7 @@ public class Indexer implements QueryInd
         }
         PrefixIndex index = new PrefixIndex(this, prefix);
         buildIndex(index);
-        indexes.put(index.getIndexNodeName(), index);
+        indexes.put(index.getDefinition().getName(), index);
         prefixIndexes.put(index.getPrefix(), index);
         queryIndexList = null;
         return index;
@@ -213,7 +218,7 @@ public class Indexer implements QueryInd
         return mk.nodeExists(PathUtils.concat(indexRootNode, name), revision);
     }
 
-    void createNodes(String path) {
+    public void createNodes(String path) {
         String rev = mk.getHeadRevision();
         JsopBuilder jsop = new JsopBuilder();
         String p = "/";
@@ -232,7 +237,7 @@ public class Indexer implements QueryInd
         revision = mk.commit(indexRootNode, jsop, revision, null);
     }
 
-    BTreePage getPageIfCached(BTree tree, BTreeNode parent, String name) {
+    public BTreePage getPageIfCached(BTree tree, BTreeNode parent, String name) {
         String p = getPath(tree, parent, name);
         return modified.get(p);
     }
@@ -243,7 +248,7 @@ public class Indexer implements QueryInd
         return PathUtils.concat(indexRoot, p);
     }
 
-    BTreePage getPage(BTree tree, BTreeNode parent, String name) {
+    public BTreePage getPage(BTree tree, BTreeNode parent, String name) {
         String p = getPath(tree, parent, name);
         BTreePage page;
         page = modified.get(p);
@@ -296,7 +301,7 @@ public class Indexer implements QueryInd
         return data;
     }
 
-    void buffer(String diff) {
+    public void buffer(String diff) {
         if (buffer == null) {
             buffer = new StringBuilder(diff);
         } else {
@@ -304,7 +309,7 @@ public class Indexer implements QueryInd
         }
     }
 
-    void modified(BTree tree, BTreePage page, boolean deleted) {
+    public void modified(BTree tree, BTreePage page, boolean deleted) {
         String indexRoot = PathUtils.concat(indexRootNode, tree.getName());
         String p = PathUtils.concat(indexRoot, INDEX_CONTENT, page.getPath());
         if (deleted) {
@@ -314,7 +319,7 @@ public class Indexer implements QueryInd
         }
     }
 
-    void moveCache(BTree tree, String oldPath) {
+    public void moveCache(BTree tree, String oldPath) {
         String indexRoot = PathUtils.concat(indexRootNode, tree.getName());
         String o = PathUtils.concat(indexRoot, INDEX_CONTENT, oldPath);
         HashMap<String, BTreePage> moved = new HashMap<String, BTreePage>();
@@ -342,7 +347,7 @@ public class Indexer implements QueryInd
         }
     }
 
-    synchronized void updateUntil(String toRevision) {
+    synchronized public void updateUntil(String toRevision) {
         if (DISABLED) {
             return;
         }
@@ -393,7 +398,7 @@ public class Indexer implements QueryInd
      * @param toRevision the new index revision
      * @return the new head revision
      */
-    String updateEnd(String toRevision) {
+    public String updateEnd(String toRevision) {
         readRevision = toRevision;
         JsopBuilder jsop = new JsopBuilder();
         jsop.tag('^').key(PathUtils.concat(INDEX_CONTENT, "rev")).value(readRevision);
@@ -422,7 +427,7 @@ public class Indexer implements QueryInd
      * @param t the changes
      * @param lastRevision
      */
-    void updateIndex(String rootPath, JsopReader t, String lastRevision) {
+    public void updateIndex(String rootPath, JsopReader t, String lastRevision) {
         while (true) {
             int r = t.read();
             if (r == JsopReader.END) {
@@ -511,7 +516,7 @@ public class Indexer implements QueryInd
             // don't index the index data itself
             return;
         }
-        for (Index index : indexes.values()) {
+        for (PIndex index : indexes.values()) {
             if (remove) {
                 index.addOrRemoveNode(n, false);
             }
@@ -586,7 +591,7 @@ public class Indexer implements QueryInd
         NodeImpl n = NodeImpl.parse(map, t, 0, path);
         if (n.hasProperty(property)) {
             n.setPath(nodePath);
-            for (Index index : indexes.values()) {
+            for (PIndex index : indexes.values()) {
                 index.addOrRemoveProperty(nodePath, property, n.getProperty(property), false);
             }
         }
@@ -599,7 +604,7 @@ public class Indexer implements QueryInd
         }
         String nodePath = PathUtils.getParentPath(path);
         String property = PathUtils.getName(path);
-        for (Index index : indexes.values()) {
+        for (PIndex index : indexes.values()) {
             index.addOrRemoveProperty(nodePath, property, value, true);
         }
     }
@@ -636,12 +641,12 @@ public class Indexer implements QueryInd
         }
     }
 
-    private void buildIndex(Index index) {
+    private void buildIndex(PIndex index) {
         // TODO index: add ability to start / stop / restart indexing; log the progress
         addRecursive(index, "/");
     }
 
-    private void addRecursive(Index index, String path) {
+    private void addRecursive(PIndex index, String path) {
         if (isInIndex(path)) {
             return;
         }
@@ -674,7 +679,7 @@ public class Indexer implements QueryInd
                 if (index instanceof PropertyIndex) {
                     qi = new PropertyContentIndex((PropertyIndex) index);
                 } else if (index instanceof PrefixIndex) {
-                    // TODO support prefix indexes in the query engine?
+                    qi = new PrefixContentIndex((PrefixIndex) index);
                 }
                 queryIndexList.add(qi);
             }
@@ -682,11 +687,11 @@ public class Indexer implements QueryInd
         return queryIndexList;
     }
 
-    PrefixIndex getPrefixIndex(String prefix) {
+    public PrefixIndex getPrefixIndex(String prefix) {
         return prefixIndexes.get(prefix);
     }
 
-    PropertyIndex getPropertyIndex(String property) {
+    public PropertyIndex getPropertyIndex(String property) {
         return propertyIndexes.get(property);
     }
 

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/Indexer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PIndex.java?rev=1375930&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PIndex.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PIndex.java Wed Aug 22 08:04:51 2012
@@ -0,0 +1,60 @@
+/*
+ * 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;
+
+import java.util.Iterator;
+
+import org.apache.jackrabbit.mk.simple.NodeImpl;
+import org.apache.jackrabbit.oak.spi.query.Index;
+
+/**
+ * An index is a lookup mechanism. It typically uses a tree to store data. It
+ * updates the tree whenever a node was changed. The index is updated
+ * automatically.
+ */
+public interface PIndex extends Index{
+
+    /**
+     * The given node was added or removed.
+     *
+     * @param node the node including (old or new) data
+     * @param add true if added, false if removed
+     */
+    void addOrRemoveNode(NodeImpl node, boolean add);
+
+    /**
+     * The given property was added or removed.
+     *
+     * @param nodePath the path of the node
+     * @param propertyName the property name
+     * @param value the old (when deleting) or new (when adding) value
+     * @param add true if added, false if removed
+     */
+    void addOrRemoveProperty(String nodePath, String propertyName,
+            String value, boolean add);
+
+    /**
+     * Get an iterator over the paths for the given value. For unique
+     * indexes, the iterator will contain at most one element.
+     *
+     * @param value the value, or null to return all indexed rows
+     * @param revision the revision
+     * @return an iterator of the paths (an empty iterator if not found)
+     */
+    Iterator<String> getPaths(String value, String revision);
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PIndex.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PrefixIndex.java (from r1375422, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/PrefixIndex.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PrefixIndex.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PrefixIndex.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/PrefixIndex.java&r1=1375422&r2=1375930&rev=1375930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/PrefixIndex.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PrefixIndex.java Wed Aug 22 08:04:51 2012
@@ -14,28 +14,45 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mk.index;
+package org.apache.jackrabbit.oak.plugins.index;
 
+import java.io.IOException;
 import java.util.Iterator;
+
 import org.apache.jackrabbit.mk.json.JsopReader;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
 import org.apache.jackrabbit.mk.simple.NodeImpl;
+import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.spi.query.IndexDefinition;
+import org.apache.jackrabbit.oak.spi.query.IndexDefinitionImpl;
+import org.apache.jackrabbit.oak.spi.query.IndexUtils;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
 
 /**
  * An index for all values with a given prefix.
  */
-public class PrefixIndex implements Index {
+public class PrefixIndex implements PIndex {
 
     private final Indexer indexer;
     private final BTree tree;
     private final String prefix;
 
+    private final IndexDefinition indexDefinition;
+
     public PrefixIndex(Indexer indexer, String prefix) {
+        this(indexer, prefix, new IndexDefinitionImpl(prefix,
+                PropertyIndexFactory.TYPE_PREFIX, PathUtils.concat(
+                        IndexUtils.DEFAULT_INDEX_HOME, prefix), false, null));
+    }
+
+    public PrefixIndex(Indexer indexer, String prefix, IndexDefinition indexDefinition) {
         this.indexer = indexer;
         this.prefix = prefix;
         this.tree = new BTree(indexer, Indexer.TYPE_PREFIX + prefix, false);
         tree.setMinSize(10);
+        this.indexDefinition = indexDefinition;
     }
 
     public static PrefixIndex fromNodeName(Indexer indexer, String nodeName) {
@@ -51,8 +68,8 @@ public class PrefixIndex implements Inde
     }
 
     @Override
-    public String getIndexNodeName() {
-        return tree.getName();
+    public IndexDefinition getDefinition() {
+        return indexDefinition;
     }
 
     @Override
@@ -128,8 +145,15 @@ public class PrefixIndex implements Inde
     }
 
     @Override
-    public boolean isUnique() {
-        return tree.isUnique();
+    public void close() throws IOException {
+        // not needed
+    }
+
+    @Override
+    public NodeState editCommit(NodeStore store, NodeState before,
+            NodeState after) throws CommitFailedException {
+        // TODO Auto-generated method stub
+        return null;
     }
 
 }

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndex.java (from r1375422, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/PropertyIndex.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndex.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndex.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/PropertyIndex.java&r1=1375422&r2=1375930&rev=1375930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/PropertyIndex.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndex.java Wed Aug 22 08:04:51 2012
@@ -14,33 +14,52 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mk.index;
+package org.apache.jackrabbit.oak.plugins.index;
 
+import java.io.IOException;
 import java.util.Iterator;
+
 import org.apache.jackrabbit.mk.json.JsopReader;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
 import org.apache.jackrabbit.mk.simple.NodeImpl;
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.spi.query.IndexDefinition;
+import org.apache.jackrabbit.oak.spi.query.IndexDefinitionImpl;
+import org.apache.jackrabbit.oak.spi.query.IndexUtils;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
 
 /**
  * A node handler that maps the property value to the key, and the path of the
  * node to the value. Only string and numbers are indexes (arrays, true, false,
  * and null are not indexes).
  */
-public class PropertyIndex implements Index {
+public class PropertyIndex implements PIndex {
 
     private final Indexer indexer;
     private final BTree tree;
     private final String propertyName;
 
-    PropertyIndex(Indexer indexer, String propertyName, boolean unique) {
+    private final IndexDefinition indexDefinition;
+
+    public PropertyIndex(Indexer indexer, String propertyName, boolean unique) {
+        this(indexer, propertyName, unique, new IndexDefinitionImpl(
+                propertyName, PropertyIndexFactory.TYPE_PREFIX,
+                PathUtils.concat(IndexUtils.DEFAULT_INDEX_HOME, propertyName),
+                false, null));
+    }
+
+    public PropertyIndex(Indexer indexer, String propertyName, boolean unique, IndexDefinition indexDefinition) {
         this.indexer = indexer;
         this.propertyName = propertyName;
         this.tree = new BTree(indexer, Indexer.TYPE_PROPERTY + propertyName +
                 (unique ? "," + Indexer.UNIQUE : ""), unique);
         tree.setMinSize(10);
+        this.indexDefinition = indexDefinition;
     }
 
-    static PropertyIndex fromNodeName(Indexer indexer, String nodeName) {
+    public static PropertyIndex fromNodeName(Indexer indexer, String nodeName) {
         if (!nodeName.startsWith(Indexer.TYPE_PROPERTY)) {
             return null;
         }
@@ -58,8 +77,8 @@ public class PropertyIndex implements In
     }
 
     @Override
-    public String getIndexNodeName() {
-        return tree.getName();
+    public IndexDefinition getDefinition() {
+        return indexDefinition;
     }
 
     @Override
@@ -132,8 +151,15 @@ public class PropertyIndex implements In
     }
 
     @Override
-    public boolean isUnique() {
-        return tree.isUnique();
+    public NodeState editCommit(NodeStore store, NodeState before,
+            NodeState after) throws CommitFailedException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public void close() throws IOException {
+        // not needed
     }
 
 }

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndexFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndexFactory.java?rev=1375930&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndexFactory.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndexFactory.java Wed Aug 22 08:04:51 2012
@@ -0,0 +1,60 @@
+/*
+ * 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;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.oak.spi.query.Index;
+import org.apache.jackrabbit.oak.spi.query.IndexDefinition;
+import org.apache.jackrabbit.oak.spi.query.IndexFactory;
+
+public class PropertyIndexFactory implements IndexFactory {
+
+    public static final String TYPE_PROPERTY = "property";
+    public static final String TYPE_PREFIX = "prefix";
+
+    private Indexer indexer;
+
+    @Override
+    public void init(MicroKernel mk) {
+        this.indexer = new Indexer(mk);
+    }
+
+    @Override
+    public String[] getTypes() {
+        return new String[] { TYPE_PREFIX, TYPE_PROPERTY };
+    }
+
+    @Override
+    public Index createIndex(IndexDefinition indexDefinition) {
+        if (TYPE_PREFIX.equals(indexDefinition.getType())) {
+            String prefix = indexDefinition.getProperties().get("prefix");
+            if (prefix != null) {
+                return new PrefixIndex(indexer, prefix, indexDefinition);
+            }
+            return null;
+        }
+        if (TYPE_PROPERTY.equals(indexDefinition.getType())) {
+            String name = indexDefinition.getProperties().get("pname");
+            if (name != null) {
+                return new PropertyIndex(indexer, name,
+                        indexDefinition.isUnique(), indexDefinition);
+            }
+        }
+        return null;
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndexFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java?rev=1375930&r1=1375929&r2=1375930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java Wed Aug 22 08:04:51 2012
@@ -18,7 +18,11 @@ package org.apache.jackrabbit.oak.plugin
 
 import static org.apache.jackrabbit.oak.plugins.lucene.FieldFactory.newPathField;
 import static org.apache.jackrabbit.oak.plugins.lucene.FieldFactory.newPropertyField;
+import static org.apache.jackrabbit.oak.spi.query.IndexUtils.DEFAULT_INDEX_HOME;
+import static org.apache.jackrabbit.oak.plugins.lucene.LuceneIndexUtils.DEFAULT_INDEX_NAME;
+import static org.apache.jackrabbit.oak.plugins.lucene.LuceneIndexUtils.INDEX_DATA_CHILD_NAME;
 import static org.apache.jackrabbit.oak.plugins.lucene.TermFactory.newPathTerm;
+import static org.apache.jackrabbit.oak.spi.query.IndexUtils.split;
 
 import java.io.IOException;
 
@@ -27,7 +31,11 @@ import javax.jcr.PropertyType;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.spi.commit.CommitEditor;
+import org.apache.jackrabbit.oak.spi.query.Index;
+import org.apache.jackrabbit.oak.spi.query.IndexDefinition;
+import org.apache.jackrabbit.oak.spi.query.IndexDefinitionImpl;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
@@ -45,7 +53,7 @@ import org.apache.tika.exception.TikaExc
 /**
  * This class updates a Lucene index when node content is changed.
  */
-public class LuceneEditor implements CommitEditor {
+public class LuceneEditor implements CommitEditor, Index {
 
     private static final Tika TIKA = new Tika();
 
@@ -67,20 +75,27 @@ public class LuceneEditor implements Com
         }
     }
 
+    private final IndexDefinition indexDefinition;
+
     private final String[] path;
 
-    public LuceneEditor(String... path) {
-        this.path = path;
+    public LuceneEditor(IndexDefinition indexDefinition) {
+        this.indexDefinition = indexDefinition;
+        this.path = split(indexDefinition.getPath(), INDEX_DATA_CHILD_NAME);
     }
 
+    /**
+     * Used for testing purposes only
+     */
     public LuceneEditor() {
-        this(LuceneIndexUtils.DEFAULT_INDEX_PATH);
+        this(new IndexDefinitionImpl(DEFAULT_INDEX_NAME,
+                LuceneIndexFactory.TYPE, PathUtils.concat(DEFAULT_INDEX_HOME,
+                        DEFAULT_INDEX_NAME), false, null));
     }
 
     @Override
-    public NodeState editCommit(
-            NodeStore store, NodeState before, NodeState after)
-            throws CommitFailedException {
+    public NodeState editCommit(NodeStore store, NodeState before,
+            NodeState after) throws CommitFailedException {
         try {
             OakDirectory directory = new OakDirectory(store, after, path);
 
@@ -96,6 +111,7 @@ public class LuceneEditor implements Com
 
             return directory.getRoot();
         } catch (IOException e) {
+            e.printStackTrace();
             throw new CommitFailedException(
                     "Failed to update the full text search index", e);
         }
@@ -121,8 +137,7 @@ public class LuceneEditor implements Com
                 throw exception;
             }
             if (modified) {
-                writer.updateDocument(
-                        newPathTerm(path),
+                writer.updateDocument(newPathTerm(path),
                         makeDocument(path, state));
             }
         }
@@ -157,8 +172,8 @@ public class LuceneEditor implements Com
         }
 
         @Override
-        public void childNodeChanged(
-                String name, NodeState before, NodeState after) {
+        public void childNodeChanged(String name, NodeState before,
+                NodeState after) {
             if (NodeStateUtils.isHidden(name)) {
                 return;
             }
@@ -199,18 +214,19 @@ public class LuceneEditor implements Com
                 throws IOException {
             writer.deleteDocuments(newPathTerm(path));
             for (ChildNodeEntry entry : state.getChildNodeEntries()) {
-                deleteSubtree(path + "/" + entry.getName(), entry.getNodeState());
+                deleteSubtree(path + "/" + entry.getName(),
+                        entry.getNodeState());
             }
         }
 
-        private static Document makeDocument(
-                String path, NodeState state) {
+        private static Document makeDocument(String path, NodeState state) {
             Document document = new Document();
             document.add(newPathField(path));
             for (PropertyState property : state.getProperties()) {
                 String pname = property.getName();
                 for (CoreValue value : property.getValues()) {
-                    document.add(newPropertyField(pname, parseStringValue(value)));
+                    document.add(newPropertyField(pname,
+                            parseStringValue(value)));
                 }
             }
             return document;
@@ -234,4 +250,13 @@ public class LuceneEditor implements Com
 
     }
 
+    @Override
+    public void close() throws IOException {
+        // TODO implement close
+    }
+
+    @Override
+    public IndexDefinition getDefinition() {
+        return indexDefinition;
+    }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java?rev=1375930&r1=1375929&r2=1375930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java Wed Aug 22 08:04:51 2012
@@ -18,7 +18,9 @@ package org.apache.jackrabbit.oak.plugin
 
 import static org.apache.jackrabbit.oak.plugins.lucene.FieldNames.PATH;
 import static org.apache.jackrabbit.oak.plugins.lucene.FieldNames.PATH_SELECTOR;
+import static org.apache.jackrabbit.oak.plugins.lucene.LuceneIndexUtils.INDEX_DATA_CHILD_NAME;
 import static org.apache.jackrabbit.oak.plugins.lucene.TermFactory.newPathTerm;
+import static org.apache.jackrabbit.oak.spi.query.IndexUtils.split;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -33,6 +35,7 @@ import org.apache.jackrabbit.oak.spi.Fil
 import org.apache.jackrabbit.oak.spi.Filter.PropertyRestriction;
 import org.apache.jackrabbit.oak.spi.IndexRow;
 import org.apache.jackrabbit.oak.spi.QueryIndex;
+import org.apache.jackrabbit.oak.spi.query.IndexDefinition;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.apache.lucene.index.DirectoryReader;
@@ -56,11 +59,15 @@ public class LuceneIndex implements Quer
 
     private final NodeStore store;
 
-    private final LuceneIndexInfo index;
+    private final IndexDefinition index;
 
-    public LuceneIndex(NodeStore store, LuceneIndexInfo index) {
+    private final String[] indexDataPath;
+
+    public LuceneIndex(NodeStore store, IndexDefinition indexDefinition) {
         this.store = store;
-        this.index = index;
+        this.index = indexDefinition;
+        this.indexDataPath = split(indexDefinition.getPath(),
+                INDEX_DATA_CHILD_NAME);
     }
 
     @Override
@@ -81,7 +88,7 @@ public class LuceneIndex implements Quer
     @Override
     public Cursor query(Filter filter, String revisionId, NodeState root) {
         try {
-            Directory directory = new OakDirectory(store, root, index.getPath());
+            Directory directory = new OakDirectory(store, root, indexDataPath);
             try {
                 IndexReader reader = DirectoryReader.open(directory);
                 try {
@@ -111,6 +118,7 @@ public class LuceneIndex implements Quer
                 directory.close();
             }
         } catch (IOException e) {
+            e.printStackTrace();
             return new PathCursor(Collections.<String> emptySet());
         }
     }
@@ -157,7 +165,7 @@ public class LuceneIndex implements Quer
                 last = pr.last.getString();
             }
 
-            if (first .equals(last) && pr.firstIncluding && pr.lastIncluding) {
+            if (first.equals(last) && pr.firstIncluding && pr.lastIncluding) {
                 qs.add(new TermQuery(new Term(name, first)));
             } else {
                 qs.add(TermRangeQuery.newStringRange(name, first, last,

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexFactory.java?rev=1375930&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexFactory.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexFactory.java Wed Aug 22 08:04:51 2012
@@ -0,0 +1,43 @@
+/*
+ * 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.lucene;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.oak.spi.query.Index;
+import org.apache.jackrabbit.oak.spi.query.IndexDefinition;
+import org.apache.jackrabbit.oak.spi.query.IndexFactory;
+
+public class LuceneIndexFactory implements IndexFactory {
+
+    public static final String TYPE = "lucene";
+
+    @Override
+    public void init(MicroKernel mk) {
+        // not needed
+    }
+
+    @Override
+    public String[] getTypes() {
+        return new String[] { TYPE };
+    }
+
+    @Override
+    public Index createIndex(IndexDefinition indexDefinition) {
+        return new LuceneEditor(indexDefinition);
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexProvider.java?rev=1375930&r1=1375929&r2=1375930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexProvider.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexProvider.java Wed Aug 22 08:04:51 2012
@@ -27,6 +27,7 @@ import org.apache.jackrabbit.oak.commons
 import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
 import org.apache.jackrabbit.oak.spi.QueryIndex;
 import org.apache.jackrabbit.oak.spi.QueryIndexProvider;
+import org.apache.jackrabbit.oak.spi.query.IndexDefinition;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.slf4j.Logger;
@@ -89,7 +90,7 @@ public class LuceneIndexProvider impleme
         }
 
         List<QueryIndex> tempIndexes = new ArrayList<QueryIndex>();
-        for (LuceneIndexInfo childIndex : getIndexInfos(index, indexPath)) {
+        for (IndexDefinition childIndex : getIndexInfos(index, indexPath)) {
             LOG.debug("adding a new lucene index instance @ {}", childIndex);
             tempIndexes.add(new LuceneIndex(store, childIndex));
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexUtils.java?rev=1375930&r1=1375929&r2=1375930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexUtils.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexUtils.java Wed Aug 22 08:04:51 2012
@@ -18,24 +18,28 @@ package org.apache.jackrabbit.oak.plugin
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
+import org.apache.jackrabbit.oak.api.CoreValueFactory;
+import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.spi.query.IndexDefinition;
+import org.apache.jackrabbit.oak.spi.query.IndexDefinitionImpl;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 public class LuceneIndexUtils {
 
-    /**
-     * switch to "oak:index" as soon as it is possible
-     */
-    public static final String DEFAULT_INDEX_HOME = "/oak-index";
+    public static final String DEFAULT_INDEX_NAME = "default-lucene";
 
-    public static final String DEFAULT_INDEX_NAME = "default";
+    public static final String INDEX_DATA_CHILD_NAME = ":data";
 
-    public static final String[] DEFAULT_INDEX_PATH = { "oak-index", "default",
-            ":data" };
+    // public static final String[] DEFAULT_INDEX_PATH = { "oak-index",
+    // "default",
+    // ":data" };
 
     private LuceneIndexUtils() {
 
@@ -46,23 +50,20 @@ public class LuceneIndexUtils {
      * You still need to call #commit afterwards to persist the changes
      * 
      * @param index
-     * @param path
      * @param indexName
      * @return
      */
-    public static Tree createIndexNode(Tree index, String path, String indexName) {
-        for (String e : PathUtils.elements(path)) {
-            if (PathUtils.denotesRoot(e)) {
-                continue;
-            }
-            if (index.hasChild(e)) {
-                index = index.getChild(e);
-            } else {
-                index = index.addChild(e);
-            }
+    public static Tree createIndexNode(Tree index, String indexName,
+            CoreValueFactory vf) {
+        if (index.hasChild(indexName)) {
+            index = index.getChild(indexName);
+        } else {
+            index = index.addChild(indexName);
         }
-        if (!index.hasChild(":data")) {
-            index.addChild(":data");
+        index.setProperty(IndexDefinition.TYPE_PROPERTY_NAME,
+                vf.createValue(LuceneIndexFactory.TYPE));
+        if (!index.hasChild(INDEX_DATA_CHILD_NAME)) {
+            index.addChild(INDEX_DATA_CHILD_NAME);
         }
         return index;
     }
@@ -72,37 +73,44 @@ public class LuceneIndexUtils {
      * Checks if any of the index's children qualifies as an index node, and
      * returns the list of good candidates.
      * 
-     * For now each child that has a :data node is considered to be a potential
-     * index
+     * For now each child that has a "type=lucene" property and a ":data" node
+     * is considered to be a potential index
      * 
      * @param indexHome
      *            the location of potential index nodes
      * @return the list of existing indexes
      */
-    public static List<LuceneIndexInfo> getIndexInfos(NodeState indexHome,
+    public static List<IndexDefinition> getIndexInfos(NodeState indexHome,
             String parentPath) {
         if (indexHome == null) {
-            return Collections.<LuceneIndexInfo> emptyList();
+            return Collections.<IndexDefinition> emptyList();
         }
-        List<String> parent = segmentPath(parentPath);
-        List<LuceneIndexInfo> tempIndexes = new ArrayList<LuceneIndexInfo>();
+        List<IndexDefinition> tempIndexes = new ArrayList<IndexDefinition>();
         for (ChildNodeEntry c : indexHome.getChildNodeEntries()) {
             NodeState child = c.getNodeState();
-            if (child.hasChildNode(":data")) {
-                List<String> childIndexPath = new ArrayList<String>(parent);
-                childIndexPath.add(c.getName());
-                childIndexPath.add(":data");
-                tempIndexes.add(new LuceneIndexInfo(c.getName(), childIndexPath));
+
+            PropertyState type = child
+                    .getProperty(IndexDefinition.TYPE_PROPERTY_NAME);
+            if (type == null
+                    || type.isArray()
+                    || !LuceneIndexFactory.TYPE.equals(type.getValue()
+                            .getString())) {
+                continue;
             }
-        }
-        return tempIndexes;
-    }
 
-    private static List<String> segmentPath(String path) {
-        List<String> pathElements = new ArrayList<String>();
-        for (String e : PathUtils.elements(path)) {
-            pathElements.add(e);
+            if (child.hasChildNode(INDEX_DATA_CHILD_NAME)) {
+                Map<String, String> props = new HashMap<String, String>();
+                for (PropertyState ps : child.getProperties()) {
+                    if (ps != null && !ps.isArray()) {
+                        String v = ps.getValue().getString();
+                        props.put(ps.getName(), v);
+                    }
+                }
+                tempIndexes.add(new IndexDefinitionImpl(c.getName(), type
+                        .getValue().getString(), PathUtils.concat(parentPath,
+                        c.getName()), false, null));
+            }
         }
-        return pathElements;
+        return tempIndexes;
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/PrefixContentIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/PrefixContentIndex.java?rev=1375930&r1=1375929&r2=1375930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/PrefixContentIndex.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/PrefixContentIndex.java Wed Aug 22 08:04:51 2012
@@ -19,10 +19,12 @@
 package org.apache.jackrabbit.oak.query.index;
 
 import java.util.Iterator;
+
 import javax.jcr.PropertyType;
-import org.apache.jackrabbit.mk.index.PrefixIndex;
+
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.kernel.CoreValueMapper;
+import org.apache.jackrabbit.oak.plugins.index.PrefixIndex;
 import org.apache.jackrabbit.oak.spi.Cursor;
 import org.apache.jackrabbit.oak.spi.Filter;
 import org.apache.jackrabbit.oak.spi.IndexRow;
@@ -89,7 +91,7 @@ public class PrefixContentIndex implemen
 
     @Override
     public String getIndexName() {
-        return index.getIndexNodeName();
+        return index.getDefinition().getName();
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/PropertyContentIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/PropertyContentIndex.java?rev=1375930&r1=1375929&r2=1375930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/PropertyContentIndex.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/PropertyContentIndex.java Wed Aug 22 08:04:51 2012
@@ -19,8 +19,8 @@
 package org.apache.jackrabbit.oak.query.index;
 
 import java.util.Iterator;
-import org.apache.jackrabbit.mk.index.PropertyIndex;
 import org.apache.jackrabbit.oak.api.CoreValue;
+import org.apache.jackrabbit.oak.plugins.index.PropertyIndex;
 import org.apache.jackrabbit.oak.spi.Cursor;
 import org.apache.jackrabbit.oak.spi.Filter;
 import org.apache.jackrabbit.oak.spi.IndexRow;
@@ -49,7 +49,7 @@ public class PropertyContentIndex implem
             // only support equality matches (for now)
             return Double.MAX_VALUE;
         }
-        boolean unique = index.isUnique();
+        boolean unique = index.getDefinition().isUnique();
         return unique ? 2 : 20;
     }
 
@@ -76,7 +76,7 @@ public class PropertyContentIndex implem
 
     @Override
     public String getIndexName() {
-        return index.getIndexNodeName();
+        return index.getDefinition().getName();
     }
 
     /**

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Index.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Index.java?rev=1375930&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Index.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Index.java Wed Aug 22 08:04:51 2012
@@ -0,0 +1,70 @@
+/*
+ * 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.spi.query;
+
+import java.io.Closeable;
+
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.spi.commit.CommitEditor;
+
+/**
+ * An index is a lookup mechanism. It typically uses a tree to store data. It
+ * updates the tree whenever a node was changed. The index is updated
+ * automatically.
+ */
+public interface Index extends CommitEditor, Closeable {
+
+    /**
+     * Get the the index definition. This contains the name, type, uniqueness
+     * and other properties.
+     * 
+     * @return the index definition
+     */
+    @Nonnull
+    IndexDefinition getDefinition();
+
+//    /**
+//     * The given node was added or removed.
+//     *
+//     * @param node the node including (old or new) data
+//     * @param add true if added, false if removed
+//     */
+//    void addOrRemoveNode(NodeImpl node, boolean add);
+//
+//    /**
+//     * The given property was added or removed.
+//     *
+//     * @param nodePath the path of the node
+//     * @param propertyName the property name
+//     * @param value the old (when deleting) or new (when adding) value
+//     * @param add true if added, false if removed
+//     */
+//    void addOrRemoveProperty(String nodePath, String propertyName,
+//            String value, boolean add);
+//
+//    /**
+//     * Get an iterator over the paths for the given value. For unique
+//     * indexes, the iterator will contain at most one element.
+//     *
+//     * @param value the value, or null to return all indexed rows
+//     * @param revision the revision
+//     * @return an iterator of the paths (an empty iterator if not found)
+//     */
+//    Iterator<String> getPaths(String value, String revision);
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Index.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexDefinition.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexDefinition.java?rev=1375930&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexDefinition.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexDefinition.java Wed Aug 22 08:04:51 2012
@@ -0,0 +1,66 @@
+/*
+ * 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.spi.query;
+
+import java.util.Map;
+
+import javax.annotation.Nonnull;
+
+/**
+ * Defines an index definition
+ * 
+ */
+public interface IndexDefinition {
+
+    String TYPE_PROPERTY_NAME = "type";
+
+    String UNIQUE_PROPERTY_NAME = "unique";
+
+    /**
+     * Get the unique index name. This is also the name of the index node.
+     * 
+     * @return the index name
+     */
+    @Nonnull
+    String getName();
+
+    /**
+     * @return the index type
+     */
+    @Nonnull
+    String getType();
+
+    /**
+     * @return the index path, includung the name as the last segment
+     */
+    @Nonnull
+    String getPath();
+
+    /**
+     * Whether each value may only appear once in the index.
+     * 
+     * @return true if unique
+     */
+    boolean isUnique();
+
+    /**
+     * @return the index properties
+     */
+    @Nonnull
+    Map<String, String> getProperties();
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexDefinition.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexDefinitionImpl.java?rev=1375930&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexDefinitionImpl.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexDefinitionImpl.java Wed Aug 22 08:04:51 2012
@@ -0,0 +1,99 @@
+/*
+ * 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.spi.query;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class IndexDefinitionImpl implements IndexDefinition {
+
+    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,
+            boolean unique, Map<String, String> properties) {
+        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>();
+        }
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public String getType() {
+        return type;
+    }
+
+    @Override
+    public String getPath() {
+        return path;
+    }
+
+    @Override
+    public boolean isUnique() {
+        return unique;
+    }
+
+    @Override
+    public Map<String, String> getProperties() {
+        return properties;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((path == null) ? 0 : path.hashCode());
+        result = prime * result + ((type == null) ? 0 : type.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        IndexDefinitionImpl other = (IndexDefinitionImpl) obj;
+        if (path == null) {
+            if (other.path != 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;
+        return true;
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexDefinitionImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexFactory.java?rev=1375930&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexFactory.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexFactory.java Wed Aug 22 08:04:51 2012
@@ -0,0 +1,44 @@
+/*
+ * 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.spi.query;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+
+public interface IndexFactory {
+
+    /**
+     * initializes the provided factory
+     */
+    void init(MicroKernel mk);
+
+    /**
+     * @return the index types that this factory can create
+     */
+    @Nonnull
+    String[] getTypes();
+
+    /**
+     * @param indexDefinition
+     * @return
+     */
+    @CheckForNull
+    Index createIndex(IndexDefinition indexDefinition);
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexManager.java?rev=1375930&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexManager.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexManager.java Wed Aug 22 08:04:51 2012
@@ -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.spi.query;
+
+import java.io.Closeable;
+import java.util.Set;
+
+import javax.annotation.Nonnull;
+
+/**
+ * <p>
+ * Index Manager keeps track of all the available indexes.
+ * </p>
+ * 
+ * <p>
+ * As a configuration reference it will use the index definitions nodes at
+ * {@link IndexUtils#DEFAULT_INDEX_HOME}.
+ * </p>
+ * 
+ * <p>
+ * TODO It *should* define an API for managing indexes (CRUD ops)
+ * </p>
+ * 
+ * <p>
+ * TODO Document simple node properties to create an index type
+ * </p>
+ * </p>
+ */
+public interface IndexManager extends Closeable {
+
+    /**
+     * Creates an index by passing the {@link IndexDefinition} to the registered
+     * {@link IndexFactory}(es)
+     * 
+     * @param indexDefinition
+     */
+    void registerIndex(IndexDefinition... indexDefinition);
+
+    void registerIndexFactory(IndexFactory factory);
+
+    void init();
+
+    @Nonnull
+    Set<IndexDefinition> getIndexes();
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexManagerImpl.java?rev=1375930&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexManagerImpl.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexManagerImpl.java Wed Aug 22 08:04:51 2012
@@ -0,0 +1,139 @@
+/*
+ * 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.spi.query;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.oak.api.ContentSession;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.ImmutableSet;
+
+public class IndexManagerImpl implements IndexManager {
+
+    // TODO implement an observation listener so that the {@link
+    // IndexManagerImpl} automatically creates new indexes based on new nodes
+    // added under {@link #indexConfigPath}
+
+    private static final Logger LOG = LoggerFactory
+            .getLogger(IndexManagerImpl.class);
+
+    private final String indexConfigPath;
+
+    private final ContentSession session;
+
+    private final MicroKernel mk;
+
+    private final Map<String, IndexFactory> indexFactories = new ConcurrentHashMap<String, IndexFactory>();
+
+    private final Map<IndexDefinition, Index> indexes = new ConcurrentHashMap<IndexDefinition, Index>();
+
+    public IndexManagerImpl(String indexConfigPath, ContentSession session,
+            MicroKernel mk) {
+        this.indexConfigPath = indexConfigPath;
+        this.session = session;
+        this.mk = mk;
+    }
+
+    @Override
+    public void registerIndexFactory(IndexFactory factory) {
+        factory.init(mk);
+        for (String type : factory.getTypes()) {
+            if (indexFactories.remove(type) != null) {
+                // TODO is override allowed?
+            }
+            indexFactories.put(type, factory);
+        }
+    }
+
+    @Override
+    public void init() {
+        //
+        // TODO hardwire default property indexes first ?
+        // registerIndexFactory(type, factory);
+        Tree definitions = session.getCurrentRoot().getTree(indexConfigPath);
+        if (definitions == null) {
+            return;
+        }
+
+        List<IndexDefinition> defs = new ArrayList<IndexDefinition>();
+        for (Tree c : definitions.getChildren()) {
+            IndexDefinition def = IndexUtils.getDefs(indexConfigPath, c);
+            if (def == null) {
+                LOG.warn("Skipping illegal index definition name {} @ {}",
+                        c.getName(), indexConfigPath);
+                continue;
+            }
+            if (indexes.get(def.getName()) != null) {
+                LOG.warn("Skipping existing index definition name {} @ {}",
+                        c.getName(), indexConfigPath);
+                continue;
+            }
+            defs.add(def);
+        }
+        registerIndex(defs.toArray(new IndexDefinition[defs.size()]));
+    }
+
+    @Override
+    public void registerIndex(IndexDefinition... indexDefinition) {
+        for (IndexDefinition def : indexDefinition) {
+            if (def == null) {
+                continue;
+            }
+            IndexFactory f = indexFactories.get(def.getType());
+            if (f == null) {
+                LOG.warn(
+                        "Skipping unknown index definition type {}, name {} @ {}",
+                        new String[] { def.getType(), indexConfigPath,
+                                def.getName() });
+                continue;
+            }
+            Index index = f.createIndex(def);
+            if (index != null) {
+                indexes.put(def, index);
+            }
+        }
+    }
+
+    @Override
+    public Set<IndexDefinition> getIndexes() {
+        return ImmutableSet.copyOf(indexes.keySet());
+    }
+
+    @Override
+    public synchronized void close() throws IOException {
+        Iterator<IndexDefinition> iterator = indexes.keySet().iterator();
+        while (iterator.hasNext()) {
+            IndexDefinition id = iterator.next();
+            try {
+                indexes.get(id).close();
+            } catch (IOException e) {
+                LOG.error("error closing index {}", id.getName(), e);
+            }
+            iterator.remove();
+        }
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexManagerImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexUtils.java?rev=1375930&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexUtils.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexUtils.java Wed Aug 22 08:04:51 2012
@@ -0,0 +1,82 @@
+/*
+ * 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.spi.query;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+
+public class IndexUtils {
+
+    /**
+     * switch to "oak:index" as soon as it is possible
+     */
+    public static final String DEFAULT_INDEX_HOME = "/oak-index";
+
+    public static IndexDefinition getDefs(String path, Tree tree) {
+        String name = tree.getName();
+        PropertyState typeProp = tree
+                .getProperty(IndexDefinition.TYPE_PROPERTY_NAME);
+        if (typeProp == null || typeProp.isArray()) {
+            return null;
+        }
+        String type = typeProp.getValue().getString();
+
+        boolean unique = false;
+        PropertyState uniqueProp = tree
+                .getProperty(IndexDefinition.UNIQUE_PROPERTY_NAME);
+        if (uniqueProp != null && !uniqueProp.isArray()) {
+            unique = uniqueProp.getValue().getBoolean();
+        }
+
+        Map<String, String> props = new HashMap<String, String>();
+        for (PropertyState ps : tree.getProperties()) {
+            if (ps != null && !ps.isArray()) {
+                String v = ps.getValue().getString();
+                props.put(ps.getName(), v);
+            }
+        }
+        return new IndexDefinitionImpl(name, type,
+                PathUtils.concat(path, name), unique, props);
+    }
+
+    /**
+     * Splits a give path into its segments and optionally appends a new path to
+     * the resulting array
+     * 
+     * @return array containing the path segments
+     */
+    public static String[] split(String pathIn, String append) {
+        List<String> paths = new ArrayList<String>();
+        for (String p : pathIn.split("/")) {
+            if (p.trim().length() != 0) {
+                paths.add(p);
+            }
+        }
+        if (append != null && append.trim().length() != 0) {
+            paths.add(append);
+        }
+
+        return paths.toArray(new String[paths.size()]);
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message