Wrong evaluation of NOT clause: test case
@@ -20,6 +20,7 @@ import com.google.common.collect.ImmutableList;
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.AbstractQueryTest;
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;
@@ -182,6 +184,52 @@ public class LuceneIndexQueryTest extends AbstractQueryTest {
}
+ @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 {
