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/06/26 14:15:06 UTC

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

Author: catholicon
Date: Wed Jun 26 14:15:06 2019
New Revision: 1862145

URL: http://svn.apache.org/viewvc?rev=1862145&view=rev
Log:
OAK-8437: direct children, exact, and parent path restrictions don't work when path transformation takes place (backport r1862093 from trunk)

Added:
    jackrabbit/oak/branches/1.10/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexPathRestrictionTest.java
      - copied unchanged from r1862093, jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexPathRestrictionTest.java
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/LucenePropertyIndex.java
    jackrabbit/oak/branches/1.10/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
    jackrabbit/oak/branches/1.10/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/query/FulltextIndexPlanner.java

Propchange: jackrabbit/oak/branches/1.10/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun 26 14:15:06 2019
@@ -1,3 +1,3 @@
 /jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1850874,1850882,1851236,1851253,1851451,1851533-1851535,1851619,1852052,1852084,1852120,1852135,1852451,1852492-1852493,1852528,1852582,1852584,1852601,1852920,1853083,1853141,1853229,1853393,1853429,1853433,1853441,1853866,1853868,1853870,1853893,1853969,1853997,1854034,1854044,1854055,1854058,1854113,1854373,1854377,1854380,1854385,1854401,1854403,1854455,1854461-1854462,1854466,1854468,1854515,1854533,1854539,1854701,1854773-1854774,1854827,1854848,1854859,1854930,1854990-1854991,1855032,1855221,1855477-1855478,1855776,1855993,1856049,1856056,1856538,1856545,1857000,1857010,1857104,1857159,1857212,1857221,1857238,1857247,1857253,1857294,1857314,1857463,1857480,1857577,1857589,1857592,1857627,1857634-1857635,1857638,1857640,1857687,1857936,1858032,1858053,1858123,1858139,1858385,1858424,1858571,1858578,1858810,1858926,1858931,1859020,1859231,1859292,1859294,1859359,1859533,1859609,1859612,1859619,1859711,1859716,1859772,1859776,1859780,1859843,1859854,1859881
 ,1860120,1860131,1860137,1860202,1860278,1860328,1860330,1860355,1860393,1860442,1860548,1860564-1860565,1861270,1861626,1862044
+/jackrabbit/oak/trunk:1850874,1850882,1851236,1851253,1851451,1851533-1851535,1851619,1852052,1852084,1852120,1852135,1852451,1852492-1852493,1852528,1852582,1852584,1852601,1852920,1853083,1853141,1853229,1853393,1853429,1853433,1853441,1853866,1853868,1853870,1853893,1853969,1853997,1854034,1854044,1854055,1854058,1854113,1854373,1854377,1854380,1854385,1854401,1854403,1854455,1854461-1854462,1854466,1854468,1854515,1854533,1854539,1854701,1854773-1854774,1854827,1854848,1854859,1854930,1854990-1854991,1855032,1855221,1855477-1855478,1855776,1855993,1856049,1856056,1856538,1856545,1857000,1857010,1857104,1857159,1857212,1857221,1857238,1857247,1857253,1857294,1857314,1857463,1857480,1857577,1857589,1857592,1857627,1857634-1857635,1857638,1857640,1857687,1857936,1858032,1858053,1858123,1858139,1858385,1858424,1858571,1858578,1858810,1858926,1858931,1859020,1859231,1859292,1859294,1859359,1859533,1859609,1859612,1859619,1859711,1859716,1859772,1859776,1859780,1859843,1859854,1859881
 ,1860120,1860131,1860137,1860202,1860278,1860328,1860330,1860355,1860393,1860442,1860548,1860564-1860565,1861270,1861626,1862044,1862093
 /jackrabbit/trunk:1345480

Modified: jackrabbit/oak/branches/1.10/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.10/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java?rev=1862145&r1=1862144&r2=1862145&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.10/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java (original)
+++ jackrabbit/oak/branches/1.10/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java Wed Jun 26 14:15:06 2019
@@ -1043,12 +1043,21 @@ public class LucenePropertyIndex extends
                 if (defn.evaluatePathRestrictions()) {
                     BooleanQuery bq = new BooleanQuery();
                     bq.add(new BooleanClause(new TermQuery(newAncestorTerm(path)), BooleanClause.Occur.MUST));
-                    bq.add(new BooleanClause(newDepthQuery(path), BooleanClause.Occur.MUST));
+                    bq.add(new BooleanClause(newDepthQuery(path, planResult), BooleanClause.Occur.MUST));
                     qs.add(bq);
                 }
                 break;
             case EXACT:
-                qs.add(new TermQuery(newPathTerm(path)));
+                // For transformed paths, we can only add path restriction if absolute path to property can be
+                // deduced
+                if (planResult.isPathTransformed()) {
+                    String parentPathSegment = planResult.getParentPathSegment();
+                    if ( ! Iterables.any(PathUtils.elements(parentPathSegment), "*"::equals)) {
+                        qs.add(new TermQuery(newPathTerm(path + parentPathSegment)));
+                    }
+                } else {
+                    qs.add(new TermQuery(newPathTerm(path)));
+                }
                 break;
             case PARENT:
                 if (denotesRoot(path)) {
@@ -1057,7 +1066,16 @@ public class LucenePropertyIndex extends
                     // is no way to say "match no documents" in Lucene
                     qs.add(new TermQuery(new Term(FieldNames.PATH, "///")));
                 } else {
-                    qs.add(new TermQuery(newPathTerm(getParentPath(path))));
+                    // For transformed paths, we can only add path restriction if absolute path to property can be
+                    // deduced
+                    if (planResult.isPathTransformed()) {
+                        String parentPathSegment = planResult.getParentPathSegment();
+                        if ( ! Iterables.any(PathUtils.elements(parentPathSegment), "*"::equals)) {
+                            qs.add(new TermQuery(newPathTerm(getParentPath(path) + parentPathSegment)));
+                        }
+                    } else {
+                        qs.add(new TermQuery(newPathTerm(getParentPath(path))));
+                    }
                 }
                 break;
             case NO_RESTRICTION:
@@ -1494,8 +1512,8 @@ public class LucenePropertyIndex extends
         }
     }
 
-    private static Query newDepthQuery(String path) {
-        int depth = PathUtils.getDepth(path) + 1;
+    private static Query newDepthQuery(String path, PlanResult planResult) {
+        int depth = PathUtils.getDepth(path) + planResult.getParentDepth() + 1;
         return NumericRangeQuery.newIntRange(FieldNames.PATH_DEPTH, depth, depth, true, true);
     }
 

Modified: jackrabbit/oak/branches/1.10/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.10/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java?rev=1862145&r1=1862144&r2=1862145&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.10/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java (original)
+++ jackrabbit/oak/branches/1.10/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java Wed Jun 26 14:15:06 2019
@@ -3330,6 +3330,59 @@ public class LucenePropertyIndexTest ext
                 "lucene:fooIndex(/oak:index/fooIndex)", asList("/d"));
     }
 
+    @Test
+    public void pathTransformationWithEvaluatePathRestriction() throws Exception {
+        // This test might feel redundant in presence of LuceneIndexPathRestrictionTest, BUT, this test
+        // gets result via query engine so the results is exactly correct. While in LuceneIndexPathRestrictionTest
+        // we're interested in how many constraint could the index resolve.. so those results would be super-set of
+        // what we see here
+
+        IndexDefinitionBuilder idxBuilder = new IndexDefinitionBuilder()
+                .noAsync().evaluatePathRestrictions();
+        idxBuilder.indexRule("nt:base").property("foo").propertyIndex();
+        Tree idx = root.getTree("/").getChild("oak:index").addChild("fooIndex");
+        idxBuilder.build(idx);
+        root.commit();
+
+        Tree rootTree = root.getTree("/").addChild("test");
+        rootTree.addChild("a").addChild("j:c").setProperty("foo", "bar");
+        rootTree.addChild("b").setProperty("foo", "bar");
+        rootTree.addChild("c").addChild("d").addChild("j:c").setProperty("foo", "bar");
+        root.commit();
+
+        // no path restriction
+        assertPlanAndQueryXPath("//*[j:c/@foo = 'bar']",
+                "lucene:fooIndex(/oak:index/fooIndex)", asList("/test/a", "/test/c/d"));
+        assertPlanAndQueryXPath("//*[*/@foo = 'bar']",
+                "lucene:fooIndex(/oak:index/fooIndex)", asList("/test/a", "/test", "/test/c/d"));
+        assertPlanAndQueryXPath("//*[d/*/@foo = 'bar']",
+                "lucene:fooIndex(/oak:index/fooIndex)", asList("/test/c"));
+
+        // any descendant
+        assertPlanAndQueryXPath("/jcr:root/test//*[j:c/@foo = 'bar']",
+                "lucene:fooIndex(/oak:index/fooIndex)", asList("/test/a", "/test/c/d"));
+        assertPlanAndQueryXPath("/jcr:root/test//*[*/@foo = 'bar']",
+                "lucene:fooIndex(/oak:index/fooIndex)", asList("/test/a", "/test/c/d"));
+        assertPlanAndQueryXPath("/jcr:root/test//*[d/*/@foo = 'bar']",
+                "lucene:fooIndex(/oak:index/fooIndex)", asList("/test/c"));
+
+        // direct children
+        assertPlanAndQueryXPath("/jcr:root/test/*[j:c/@foo = 'bar']",
+                "lucene:fooIndex(/oak:index/fooIndex)", asList("/test/a"));
+        assertPlanAndQueryXPath("/jcr:root/test/*[*/@foo = 'bar']",
+                "lucene:fooIndex(/oak:index/fooIndex)", asList("/test/a"));
+        assertPlanAndQueryXPath("/jcr:root/test/*[d/*/@foo = 'bar']",
+                "lucene:fooIndex(/oak:index/fooIndex)", asList("/test/c"));
+
+        // exact path
+        assertPlanAndQueryXPath("/jcr:root/test/a[j:c/@foo = 'bar']",
+                "lucene:fooIndex(/oak:index/fooIndex)", asList("/test/a"));
+        assertPlanAndQueryXPath("/jcr:root/test/a[*/@foo = 'bar']",
+                "lucene:fooIndex(/oak:index/fooIndex)", asList("/test/a"));
+        assertPlanAndQueryXPath("/jcr:root/test/c[d/*/@foo = 'bar']",
+                "lucene:fooIndex(/oak:index/fooIndex)", asList("/test/c"));
+    }
+
     private void assertPlanAndQueryXPath(String query, String planExpectation, List<String> paths) throws ParseException {
         assertXpathPlan(query, planExpectation);
         assertQuery(query, XPATH, paths, false);

Modified: jackrabbit/oak/branches/1.10/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/query/FulltextIndexPlanner.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.10/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/query/FulltextIndexPlanner.java?rev=1862145&r1=1862144&r2=1862145&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.10/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/query/FulltextIndexPlanner.java (original)
+++ jackrabbit/oak/branches/1.10/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/query/FulltextIndexPlanner.java Wed Jun 26 14:15:06 2019
@@ -977,6 +977,14 @@ public class FulltextIndexPlanner {
             return relativize;
         }
 
+        public int getParentDepth() {
+            return parentDepth;
+        }
+
+        public String getParentPathSegment() {
+            return parentPathSegment;
+        }
+
         public boolean isUniquePathsRequired() {
             return uniquePathsRequired;
         }