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 ca...@apache.org on 2019/02/12 14:08:51 UTC

svn commit: r1853440 - in /jackrabbit/oak/branches/1.10: ./ oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/ oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/

Author: catholicon
Date: Tue Feb 12 14:08:50 2019
New Revision: 1853440

URL: http://svn.apache.org/viewvc?rev=1853440&view=rev
Log:
OAK-8041: IndexDefinitnionBuider should support facets and boost for property definitions (backported r1853435 from trunk)
OAK-8042: IndexDefinitnionBuider should support deprecated properties on index definition (backported r1853434 from trunk)

Modified:
    jackrabbit/oak/branches/1.10/   (props changed)
    jackrabbit/oak/branches/1.10/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilder.java
    jackrabbit/oak/branches/1.10/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilderTest.java

Propchange: jackrabbit/oak/branches/1.10/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Feb 12 14:08:50 2019
@@ -1,3 +1,3 @@
 /jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1851236,1851253,1851451,1852052,1852084,1852451,1852492-1852493,1852920
+/jackrabbit/oak/trunk:1851236,1851253,1851451,1852052,1852084,1852451,1852492-1852493,1852920,1853434-1853435
 /jackrabbit/trunk:1345480

Modified: jackrabbit/oak/branches/1.10/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.10/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilder.java?rev=1853440&r1=1853439&r2=1853440&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.10/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilder.java (original)
+++ jackrabbit/oak/branches/1.10/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilder.java Tue Feb 12 14:08:50 2019
@@ -48,7 +48,9 @@ import static org.apache.jackrabbit.JcrC
 import static org.apache.jackrabbit.JcrConstants.NT_UNSTRUCTURED;
 import static org.apache.jackrabbit.oak.api.Type.NAME;
 import static org.apache.jackrabbit.oak.api.Type.STRINGS;
+import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEPRECATED;
 import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.TYPE_LUCENE;
+import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.FIELD_BOOST;
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
 
 public final class IndexDefinitionBuilder {
@@ -123,6 +125,11 @@ public final class IndexDefinitionBuilde
         return this;
     }
 
+    public IndexDefinitionBuilder deprecated() {
+        tree.setProperty(INDEX_DEPRECATED, true);
+        return this;
+    }
+
     public IndexDefinitionBuilder async(String ... asyncVals){
         tree.removeProperty("async");
         tree.setProperty("async", asList(asyncVals), STRINGS);
@@ -391,11 +398,21 @@ public final class IndexDefinitionBuilde
             return this;
         }
 
+        public PropertyRule facets(){
+            propTree.setProperty(FulltextIndexConstants.PROP_FACETS, true);
+            return this;
+        }
+
         public PropertyRule weight(int weight){
             propTree.setProperty(FulltextIndexConstants.PROP_WEIGHT, weight);
             return this;
         }
 
+        public PropertyRule boost(float boost){
+            propTree.setProperty(FIELD_BOOST, (double)boost, Type.DOUBLE);
+            return this;
+        }
+
         public PropertyRule valuePattern(String valuePattern){
             propTree.setProperty(IndexConstants.VALUE_PATTERN, valuePattern);
             return this;

Modified: jackrabbit/oak/branches/1.10/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.10/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilderTest.java?rev=1853440&r1=1853439&r2=1853440&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.10/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilderTest.java (original)
+++ jackrabbit/oak/branches/1.10/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilderTest.java Tue Feb 12 14:08:50 2019
@@ -37,8 +37,11 @@ import org.junit.After;
 import org.junit.Test;
 
 import static java.util.Arrays.asList;
+import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEPRECATED;
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_PROPERTY_NAME;
 import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.AGGREGATES;
+import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.FIELD_BOOST;
+import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.PROP_FACETS;
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
 import static org.junit.Assert.*;
 
@@ -313,4 +316,51 @@ public class IndexDefinitionBuilderTest
         NodeState state = builder.build();
         assertFalse(NodeStateUtils.getNode(state, "/indexRules/nt:file/properties").exists());
     }
+
+    @Test
+    public void deprecated() {
+        NodeState state = builder.build();
+        assertFalse("By default index isn't deprecated", state.getBoolean(INDEX_DEPRECATED));
+
+        state = builder.deprecated().build();
+        assertTrue("Index must be deprecated if marked so", state.getBoolean(INDEX_DEPRECATED));
+    }
+
+    @Test
+    public void boost() {
+        builder.indexRule("nt:base")
+                .property("foo1").boost(1.0f).enclosingRule()
+                .property("foo2").boost(2.0f);
+
+        NodeState state = builder.build();
+
+        NodeState foo1 = NodeStateUtils.getNode(state, "indexRules/nt:base/properties/foo1");
+        assertTrue(foo1.exists());
+        assertEquals("Incorrectly set boost",
+                1.0f, foo1.getProperty(FIELD_BOOST).getValue(Type.DOUBLE).floatValue(), 0.0001);
+
+        NodeState foo2 = NodeStateUtils.getNode(state, "indexRules/nt:base/properties/foo2");
+        assertTrue(foo2.exists());
+        assertEquals("Incorrectly set boost",
+                2.0f, foo2.getProperty(FIELD_BOOST).getValue(Type.DOUBLE).floatValue(), 0.0001);
+    }
+
+    @Test
+    public void facets() {
+        builder.indexRule("nt:base")
+                .property("foo1").facets().enclosingRule()
+                .property("foo2").propertyIndex();
+
+        NodeState state = builder.build();
+
+        NodeState foo1 = NodeStateUtils.getNode(state, "indexRules/nt:base/properties/foo1");
+        assertTrue(foo1.exists());
+        assertTrue("Incorrectly set facets property",
+                foo1.getBoolean(PROP_FACETS));
+
+        NodeState foo2 = NodeStateUtils.getNode(state, "indexRules/nt:base/properties/foo2");
+        assertTrue(foo2.exists());
+        assertFalse("Incorrectly existing facets property",
+                foo2.hasProperty(PROP_FACETS));
+    }
 }
\ No newline at end of file