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 ch...@apache.org on 2014/11/16 08:19:29 UTC

svn commit: r1639973 - /jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java

Author: chetanm
Date: Sun Nov 16 07:19:29 2014
New Revision: 1639973

URL: http://svn.apache.org/r1639973
Log:
OAK-2261 - Enable support for NodeType based indexing rules (WIP)

* Set primaryType for runtime create NodeStates
* Use property name as node name unless its not suitable to be used i.e. in relative prop name case or regEx

Modified:
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java?rev=1639973&r1=1639972&r2=1639973&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java Sun Nov 16 07:19:29 2014
@@ -659,6 +659,10 @@ class IndexDefinition {
             Map<String, PropertyDefinition> propDefns = newHashMap();
             NodeState propNode = config.getChildNode(LuceneIndexConstants.PROP_NODE);
 
+            if (!propNode.exists()){
+                return Collections.emptyMap();
+            }
+
             if (!hasOrderableChildren(propNode)){
                 log.warn("Properties node for [{}] does not have orderable " +
                 "children in [{}]", this, IndexDefinition.this);
@@ -744,6 +748,20 @@ class IndexDefinition {
 
     //~---------------------------------------------< compatibility >
 
+    public void updateDefinition(NodeBuilder indexDefn){
+        //TODO Remove existing config once transformed config is persisted
+        NodeState rulesState = definition.getChildNode(LuceneIndexConstants.INDEX_RULES);
+        if (!rulesState.exists()){
+            rulesState = createIndexRules(definition).getNodeState();
+            indexDefn.setChildNode(LuceneIndexConstants.INDEX_RULES, rulesState);
+            log.info("Updated index definition for {}", this);
+            //indexDefn.removeProperty(DECLARING_NODE_TYPES);
+            //indexDefn.removeProperty(INCLUDE_PROPERTY_NAMES);
+            //indexDefn.removeProperty(EXCLUDE_PROPERTY_NAMES);
+            //indexDefn.removeProperty(ORDERED_PROP_NAMES);
+        }
+    }
+
     /**
      * Constructs IndexingRule based on earlier format of index configuration
      */
@@ -786,16 +804,22 @@ class IndexDefinition {
 
         for (String typeName : declaringNodeTypes){
             NodeBuilder rule = builder.child(typeName);
-
+            markAsNtUnstructured(rule);
             List<String> propNodeNames = newArrayListWithCapacity(propNamesSet.size());
             NodeBuilder propNodes = rule.child(PROP_NODE);
             int i = 0;
             for (String propName : propNames){
-                String propNodeName = "prop" + i++;
+                String propNodeName = propName;
+
+                //For proper propName use the propName as childNode name
+                if(RelativeProperty.isRelativeProperty(propName)
+                        || propName.equals(includeAllProp)){
+                    propNodeName = "prop" + i++;
+                }
                 propNodeNames.add(propNodeName);
 
                 NodeBuilder prop = propNodes.child(propNodeName);
-
+                markAsNtUnstructured(prop);
                 prop.setProperty(LuceneIndexConstants.PROP_NAME, propName);
 
                 if (excludes.contains(propName)){
@@ -835,8 +859,10 @@ class IndexDefinition {
             }
 
             propNodes.setProperty(OAK_CHILD_ORDER, propNodeNames ,NAMES);
+            markAsNtUnstructured(propNodes);
         }
 
+        markAsNtUnstructured(builder);
         builder.setProperty(OAK_CHILD_ORDER, declaringNodeTypes ,NAMES);
         return builder;
     }
@@ -965,4 +991,8 @@ class IndexDefinition {
         }
         return ImmutableSet.copyOf(propNames);
     }
+
+    private static void markAsNtUnstructured(NodeBuilder nb){
+        nb.setProperty(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED, Type.NAME);
+    }
 }