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 th...@apache.org on 2017/10/27 14:53:09 UTC

svn commit: r1813539 - /jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexQueryTest.java

Author: thomasm
Date: Fri Oct 27 14:53:08 2017
New Revision: 1813539

URL: http://svn.apache.org/viewvc?rev=1813539&view=rev
Log:
OAK-3371 Wrong evaluation of NOT clause: test case

Modified:
    jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexQueryTest.java

Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexQueryTest.java?rev=1813539&r1=1813538&r2=1813539&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexQueryTest.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexQueryTest.java Fri Oct 27 14:53:08 2017
@@ -20,6 +20,7 @@ import com.google.common.collect.Immutab
 
 import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.List;
 
 import org.apache.jackrabbit.oak.Oak;
 import org.apache.jackrabbit.oak.api.ContentRepository;
@@ -31,6 +32,7 @@ import org.apache.jackrabbit.oak.query.A
 import org.apache.jackrabbit.oak.spi.commit.Observer;
 import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
+import org.junit.Assert;
 import org.junit.Ignore;
 import org.junit.Test;
 
@@ -68,10 +70,10 @@ public class LuceneIndexQueryTest extend
         TestUtil.enableFunctionIndex(props, "length([name])");
         TestUtil.enableFunctionIndex(props, "lower([name])");
         TestUtil.enableFunctionIndex(props, "upper([name])");
-        
-        root.commit();                
+
+        root.commit();
     }
-    
+
     @Override
     protected ContentRepository createRepository() {
         return getOakRepo().createContentRepository();
@@ -85,7 +87,7 @@ public class LuceneIndexQueryTest extend
             .with((Observer) provider)
             .with(new LuceneIndexEditorProvider());
     }
-    
+
     @Test
     public void sql1() throws Exception {
         test("sql1.txt");
@@ -95,7 +97,7 @@ public class LuceneIndexQueryTest extend
     public void sql2() throws Exception {
         test("sql2.txt");
     }
-    
+
     @Test
     public void sql2FullText() throws Exception {
         test("sql2-fulltext.txt");
@@ -182,6 +184,52 @@ public class LuceneIndexQueryTest extend
 
     }
 
+    @Test
+    public void containsNot() throws Exception {
+
+        // see also OAK-3371
+        // "if we have only NOT CLAUSES we have to add a match all docs (*.*) for the
+        // query to work"
+
+        executeQuery("/jcr:root//*[jcr:contains(@a,'-test*')]", "xpath", false);
+
+        String planPrefix = "[nt:base] as [a] /* lucene:test-index(/oak:index/test-index) ";
+
+        assertXPathPlan("/jcr:root//*[@a]",
+                planPrefix + "a:[* TO *]");
+
+        assertXPathPlan("/jcr:root//*[jcr:contains(., '*')]",
+                planPrefix + ":fulltext:* ft:(\"*\")");
+
+        assertXPathPlan("/jcr:root//*[jcr:contains(@a,'*')]",
+                planPrefix + "full:a:* ft:(a:\"*\")");
+
+        assertXPathPlan("/jcr:root//*[jcr:contains(@a,'hello -world')]",
+                planPrefix + "+full:a:hello -full:a:world ft:(a:\"hello\" -a:\"world\")");
+
+        assertXPathPlan("/jcr:root//*[jcr:contains(@a,'test*')]",
+                planPrefix + "full:a:test* ft:(a:\"test*\")");
+
+        assertXPathPlan("/jcr:root//*[jcr:contains(@a,'-test')]",
+                planPrefix + "-full:a:test *:* ft:(-a:\"test\")");
+
+        assertXPathPlan("/jcr:root//*[jcr:contains(@a,'-test*')]",
+                planPrefix + "-full:a:test* *:* ft:(-a:\"test*\")");
+
+        assertXPathPlan("/jcr:root//*[jcr:contains(., '-*')]",
+                planPrefix + "-:fulltext:* *:* ft:(-\"*\")");
+
+    }
+
+    private void assertXPathPlan(String xpathQuery, String expectedPlan) {
+        List<String> result = executeQuery("explain " + xpathQuery, "xpath", false);
+        String plan = result.get(0);
+        int newline = plan.indexOf('\n');
+        if (newline >= 0) {
+            plan = plan.substring(0, newline);
+        }
+        Assert.assertEquals(expectedPlan, plan);
+    }
     @Ignore("OAK-2424")
     @Test
     public void containsDash() throws Exception {
@@ -312,7 +360,7 @@ public class LuceneIndexQueryTest extend
 
     @Test
     public void testRepSimilarAsNativeQuery() throws Exception {
-        String nativeQueryString = "select [jcr:path] from [nt:base] where " + 
+        String nativeQueryString = "select [jcr:path] from [nt:base] where " +
                 "native('lucene', 'mlt?stream.body=/test/a&mlt.fl=:path&mlt.mindf=0&mlt.mintf=0')";
         Tree test = root.getTree("/").addChild("test");
         test.addChild("a").setProperty("text", "Hello World");
@@ -326,7 +374,7 @@ public class LuceneIndexQueryTest extend
         assertEquals("/test/b", result.next());
         assertFalse(result.hasNext());
     }
-    
+
     @Test
     public void testRepSimilarQuery() throws Exception {
         String query = "select [jcr:path] from [nt:base] where similar(., '/test/a')";
@@ -415,7 +463,7 @@ public class LuceneIndexQueryTest extend
             walktree(t1);
         }
     }
-    
+
     private static Tree child(Tree t, String n, String type) {
         Tree t1 = t.addChild(n);
         t1.setProperty(JCR_PRIMARYTYPE, type, Type.NAME);
@@ -426,7 +474,7 @@ public class LuceneIndexQueryTest extend
     public void oak3371() throws Exception {
         setTraversalEnabled(false);
         Tree t, t1;
-        
+
         t = root.getTree("/");
         t = child(t, "test", NT_UNSTRUCTURED);
         t1 = child(t, "a", NT_UNSTRUCTURED);