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/12/10 11:36:51 UTC

svn commit: r1644366 - in /jackrabbit/oak/trunk/oak-lucene/src: main/java/org/apache/jackrabbit/oak/plugins/index/lucene/ test/java/org/apache/jackrabbit/oak/plugins/index/lucene/

Author: chetanm
Date: Wed Dec 10 10:36:51 2014
New Revision: 1644366

URL: http://svn.apache.org/r1644366
Log:
OAK-2330 - Field boost not working if the property for indexing is picked using aggregate index rules

Property should be included for nodeScope index in all cases i.e. relative or direct

Modified:
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java
    jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
    jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/TestUtil.java

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java?rev=1644366&r1=1644365&r2=1644366&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java Wed Dec 10 10:36:51 2014
@@ -291,7 +291,7 @@ public class LuceneIndexEditor implement
                 dirty |= addTypedOrderedFields(fields, property, pname, pd);
             }
 
-            dirty |= indexProperty(path, fields, state, property, pname, false, pd);
+            dirty |= indexProperty(path, fields, state, property, pname, pd);
         }
 
         dirty |= indexAggregates(path, fields, state);
@@ -335,7 +335,6 @@ public class LuceneIndexEditor implement
                                   NodeState state,
                                   PropertyState property,
                                   String pname,
-                                  boolean aggregateMode,
                                   PropertyDefinition pd) throws CommitFailedException {
         boolean includeTypeForFullText = indexingRule.includePropertyType(property.getType().tag());
         if (Type.BINARY.tag() == property.getType().tag()
@@ -358,7 +357,7 @@ public class LuceneIndexEditor implement
                         fields.add(newPropertyField(analyzedPropName, value, !pd.skipTokenization(pname), pd.stored));
                     }
 
-                    if (pd.nodeScopeIndex && !aggregateMode) {
+                    if (pd.nodeScopeIndex) {
                         Field field = newFulltextField(value);
                         field.setBoost(pd.boost);
                         fields.add(field);
@@ -533,7 +532,7 @@ public class LuceneIndexEditor implement
                             result.propertyPath, result.pd);
                 }
                 dirty |= indexProperty(path, fields, state, result.propertyState,
-                        result.propertyPath, true, result.pd);
+                        result.propertyPath, result.pd);
 
                 if (dirty) {
                     dirtyFlag.set(true);

Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java?rev=1644366&r1=1644365&r2=1644366&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java Wed Dec 10 10:36:51 2014
@@ -61,6 +61,7 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.ORDERED_PROP_NAMES;
 import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.PROP_NODE;
 import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorTest.createCal;
+import static org.apache.jackrabbit.oak.plugins.index.lucene.TestUtil.useV2;
 import static org.apache.jackrabbit.oak.plugins.index.property.OrderedIndex.OrderDirection;
 import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
 import static org.junit.Assert.assertEquals;
@@ -745,6 +746,49 @@ public class LucenePropertyIndexTest ext
         assertOrderedQuery(queryString, asList("/test/c", "/test/a", "/test/b"), XPATH, true);
     }
 
+    @Test
+    public void indexTimeFieldBoostAndRelativeProperty() throws Exception {
+        // Index Definition
+        Tree index = root.getTree("/");
+        Tree indexDefn = createTestIndexNode(index, LuceneIndexConstants.TYPE_LUCENE);
+        useV2(indexDefn);
+
+        addPropertyDefn(indexDefn, "jcr:content/metadata/title", 4.0);
+        addPropertyDefn(indexDefn, "jcr:content/metadata/title2", 2.0);
+        addPropertyDefn(indexDefn, "propa", 1.0);
+
+        root.commit();
+
+        // create test data
+        Tree test = root.getTree("/").addChild("test");
+        usc(test, "a").setProperty("propa", "foo foo foo");
+        usc(test, "b").addChild("jcr:content").addChild("metadata").setProperty("title", "foo");
+        usc(test, "c").addChild("jcr:content").addChild("metadata").setProperty("title2", "foo");
+        root.commit();
+
+        String queryString = "//element(*, oak:Unstructured)[jcr:contains(., 'foo' )]";
+        // verify results ordering
+        // which should be /test/c (boost = 4.0), /test/a(boost = 2.0), /test/b (1.0)
+        assertOrderedQuery(queryString, asList("/test/b", "/test/c", "/test/a"), XPATH, true);
+    }
+
+    private Tree usc(Tree parent, String childName){
+        Tree child = parent.addChild(childName);
+        child.setProperty(JcrConstants.JCR_PRIMARYTYPE, "oak:Unstructured", Type.NAME);
+        return child;
+    }
+
+    private Tree addPropertyDefn(Tree indexDefn, String propName, double boost){
+        Tree props = TestUtil.newRulePropTree(indexDefn, "oak:Unstructured");
+        Tree prop = props.addChild(TestUtil.unique("prop"));
+        prop.setProperty(LuceneIndexConstants.PROP_NAME, propName);
+        prop.setProperty(LuceneIndexConstants.PROP_PROPERTY_INDEX, true);
+        prop.setProperty(LuceneIndexConstants.PROP_ANALYZED, true);
+        prop.setProperty(LuceneIndexConstants.PROP_NODE_SCOPE_INDEX, true);
+        prop.setProperty(LuceneIndexConstants.FIELD_BOOST, boost);
+        return prop;
+    }
+
     private void assertOrderedQuery(String sql, List<String> paths) {
         assertOrderedQuery(sql, paths, SQL2, false);
     }

Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/TestUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/TestUtil.java?rev=1644366&r1=1644365&r2=1644366&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/TestUtil.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/TestUtil.java Wed Dec 10 10:36:51 2014
@@ -104,7 +104,7 @@ public class TestUtil {
         }
     }
 
-    private static String unique(String name){
+    static String unique(String name){
         return name + COUNTER.getAndIncrement();
     }
 }