diff --git a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java index 214ddfe00db..7d4c6bf82c3 100644 --- a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java +++ b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java @@ -44,7 +44,6 @@ import javax.jcr.PropertyType; import org.apache.jackrabbit.guava.common.collect.ComparisonChain; -import org.apache.jackrabbit.guava.common.collect.ImmutableList; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Maps; import org.apache.jackrabbit.guava.common.io.CountingInputStream; @@ -106,7 +105,6 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; -import static java.util.Arrays.asList; import static org.apache.jackrabbit.JcrConstants.JCR_CONTENT; import static org.apache.jackrabbit.JcrConstants.JCR_DATA; import static org.apache.jackrabbit.JcrConstants.NT_FILE; @@ -122,7 +120,6 @@ import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.QUERY_PATHS; import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_PROPERTY_NAME; import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME; -import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.PROPDEF_PROP_NODE_NAME; import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.TIKA; import static org.apache.jackrabbit.oak.plugins.index.lucene.TestUtil.child; import static org.apache.jackrabbit.oak.plugins.index.lucene.TestUtil.newNodeAggregator; @@ -132,7 +129,6 @@ import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.INCLUDE_PROPERTY_NAMES; import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.ORDERED_PROP_NAMES; import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.PROP_ANALYZED; -import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.PROP_NAME; import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.PROP_NODE; import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.PROP_PROPERTY_INDEX; import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.PROP_RANDOM_SEED; @@ -264,28 +260,6 @@ private Tree createFulltextIndex(Tree index, String name) throws CommitFailedExc return TestUtil.createFulltextIndex(index, name); } - @Test - public void indexSelection() throws Exception { - createIndex("test1", Set.of("propa", "propb")); - createIndex("test2", Set.of("propc")); - - Tree test = root.getTree("/").addChild("test"); - test.addChild("a").setProperty("propa", "foo"); - test.addChild("b").setProperty("propa", "foo"); - test.addChild("c").setProperty("propa", "foo2"); - test.addChild("d").setProperty("propc", "foo"); - test.addChild("e").setProperty("propd", "foo"); - root.commit(); - - String propaQuery = "select [jcr:path] from [nt:base] where [propa] = 'foo'"; - assertThat(explain(propaQuery), containsString("lucene:test1")); - assertThat(explain("select [jcr:path] from [nt:base] where [propc] = 'foo'"), containsString("lucene:test2")); - - assertQuery(propaQuery, asList("/test/a", "/test/b")); - assertQuery("select [jcr:path] from [nt:base] where [propa] = 'foo2'", asList("/test/c")); - assertQuery("select [jcr:path] from [nt:base] where [propc] = 'foo'", asList("/test/d")); - } - @Test public void indexSelectionVsNodeType() throws Exception { Tree luceneIndex = createIndex("test1", Set.of("propa")); @@ -366,11 +340,11 @@ public void declaringNodeTypeSameProp() throws Exception { String propabQuery = "select [jcr:path] from [nt:unstructured] where [propa] = 'foo'"; assertThat(explain(propabQuery), containsString("lucene:test2")); - assertQuery(propabQuery, asList("/test/a", "/test/b")); + assertQuery(propabQuery, List.of("/test/a", "/test/b")); String propcdQuery = "select [jcr:path] from [nt:base] where [propa] = 'foo'"; assertThat(explain(propcdQuery), containsString("lucene:test1")); - assertQuery(propcdQuery, asList("/test/a", "/test/b", "/test/c", "/test/d")); + assertQuery(propcdQuery, List.of("/test/a", "/test/b", "/test/c", "/test/d")); } @Test @@ -399,11 +373,11 @@ public void declaringNodeTypeSingleIndex() throws Exception { String propabQuery = "select [jcr:path] from [nt:unstructured] where [propb] = 'baz' and " + "[propa] = 'foo'"; assertThat(explain(propabQuery), containsString("lucene:test2")); - assertQuery(propabQuery, asList("/test/a", "/test/b")); + assertQuery(propabQuery, List.of("/test/a", "/test/b")); String propNoIdxQuery = "select [jcr:path] from [nt:base] where [propb] = 'baz'"; assertThat(explain(propNoIdxQuery), containsString("no-index")); - assertQuery(propNoIdxQuery, ImmutableList.of()); + assertQuery(propNoIdxQuery, List.of()); } @Test @@ -426,7 +400,7 @@ public void usedAsNodeTypeIndex() throws Exception { String propabQuery = "select [jcr:path] from [nt:file]"; assertThat(explain(propabQuery), containsString("lucene:test2")); - assertQuery(propabQuery, asList("/test/a", "/test/b", "/test")); + assertQuery(propabQuery, List.of("/test/a", "/test/b", "/test")); } @Test @@ -452,7 +426,7 @@ public void usedAsNodeTypeIndex2() throws Exception { String propabQuery = "select [jcr:path] from [nt:file]"; assertThat(explain(propabQuery), containsString("lucene:test2")); - assertQuery(propabQuery, asList("/test/a", "/test/b", "/test")); + assertQuery(propabQuery, List.of("/test/a", "/test/b", "/test")); } private static Tree setNodeType(Tree t, String typeName){ @@ -477,62 +451,14 @@ public void nodeName() throws Exception{ String propabQuery = "select [jcr:path] from [nt:base] where LOCALNAME() = 'foo'"; assertThat(explain(propabQuery), containsString(":nodeName:foo")); - assertQuery(propabQuery, asList("/foo")); - assertQuery("select [jcr:path] from [nt:base] where LOCALNAME() = 'bar'", asList("/test/bar")); - assertQuery("select [jcr:path] from [nt:base] where LOCALNAME() LIKE 'foo'", asList("/foo")); - assertQuery("select [jcr:path] from [nt:base] where LOCALNAME() LIKE 'camel%'", asList("/camelCase")); - - assertQuery("select [jcr:path] from [nt:base] where NAME() = 'bar'", asList("/test/bar")); - assertQuery("select [jcr:path] from [nt:base] where NAME() LIKE 'foo'", asList("/foo")); - assertQuery("select [jcr:path] from [nt:base] where NAME() LIKE 'camel%'", asList("/camelCase")); - } - - //OAK-3825 - @Test - public void nodeNameViaPropDefinition() throws Exception{ - //make index - Tree idx = createIndex("test1", Collections.EMPTY_SET); - useV2(idx); - Tree rules = idx.addChild(FulltextIndexConstants.INDEX_RULES); - rules.setOrderableChildren(true); - Tree rule = rules.addChild("nt:base"); - Tree propDef = rule.addChild(PROP_NODE).addChild("nodeName"); - propDef.setProperty(PROP_NAME, PROPDEF_PROP_NODE_NAME); - propDef.setProperty(PROP_PROPERTY_INDEX, true); - root.commit(); - - //add content - Tree test = root.getTree("/"); - test.addChild("foo"); - test.addChild("camelCase"); - test.addChild("test").addChild("bar"); - root.commit(); - - //test - String propabQuery = "select [jcr:path] from [nt:base] where LOCALNAME() = 'foo'"; - assertThat(explain(propabQuery), containsString(":nodeName:foo")); - assertQuery(propabQuery, asList("/foo")); - assertQuery("select [jcr:path] from [nt:base] where LOCALNAME() = 'bar'", asList("/test/bar")); - assertQuery("select [jcr:path] from [nt:base] where LOCALNAME() LIKE 'foo'", asList("/foo")); - assertQuery("select [jcr:path] from [nt:base] where LOCALNAME() LIKE 'camel%'", asList("/camelCase")); + assertQuery(propabQuery, List.of("/foo")); + assertQuery("select [jcr:path] from [nt:base] where LOCALNAME() = 'bar'", List.of("/test/bar")); + assertQuery("select [jcr:path] from [nt:base] where LOCALNAME() LIKE 'foo'", List.of("/foo")); + assertQuery("select [jcr:path] from [nt:base] where LOCALNAME() LIKE 'camel%'", List.of("/camelCase")); - assertQuery("select [jcr:path] from [nt:base] where NAME() = 'bar'", asList("/test/bar")); - assertQuery("select [jcr:path] from [nt:base] where NAME() LIKE 'foo'", asList("/foo")); - assertQuery("select [jcr:path] from [nt:base] where NAME() LIKE 'camel%'", asList("/camelCase")); - } - - @Test - public void emptyIndex() throws Exception{ - Tree idx = createIndex("test1", Set.of("propa", "propb")); - idx.addChild(PROP_NODE).addChild("propa"); - root.commit(); - - Tree test = root.getTree("/").addChild("test"); - test.addChild("a"); - test.addChild("b"); - root.commit(); - - assertThat(explain("select [jcr:path] from [nt:base] where [propa] = 'foo'"), containsString("lucene:test1")); + assertQuery("select [jcr:path] from [nt:base] where NAME() = 'bar'", List.of("/test/bar")); + assertQuery("select [jcr:path] from [nt:base] where NAME() LIKE 'foo'", List.of("/foo")); + assertQuery("select [jcr:path] from [nt:base] where NAME() LIKE 'camel%'", List.of("/camelCase")); } @Test @@ -619,8 +545,8 @@ public void likeQueryOnPropertiesWithExcludedPrefixes() throws Exception { assertThat(explain("SELECT * FROM [nt:unstructured] as [content] WHERE [content].[references] LIKE '/a/b/d%'"), containsString("luceneQuery: references:/a/b/d*")); - assertQuery("SELECT [jcr:path] FROM [nt:base] as [content] WHERE [content].[references] LIKE '/a/b/c%'", SQL2, asList()); - assertQuery("SELECT [jcr:path] FROM [nt:base] WHERE references LIKE '/a/b/d%'", asList("/test/b")); + assertQuery("SELECT [jcr:path] FROM [nt:base] as [content] WHERE [content].[references] LIKE '/a/b/c%'", SQL2, List.of()); + assertQuery("SELECT [jcr:path] FROM [nt:base] WHERE references LIKE '/a/b/d%'", List.of("/test/b")); } @Test @@ -678,15 +604,15 @@ public void rangeQueriesWithLong() throws Exception { assertThat(explain("select [jcr:path] from [nt:base] where [propa] >= 20"), containsString("lucene:test1")); - assertQuery("select [jcr:path] from [nt:base] where [propa] >= 20", asList("/test/b", "/test/c")); - assertQuery("select [jcr:path] from [nt:base] where [propa] >= 20", asList("/test/b", "/test/c")); - assertQuery("select [jcr:path] from [nt:base] where [propa] = 20", asList("/test/b")); - assertQuery("select [jcr:path] from [nt:base] where [propa] <= 20", asList("/test/b", "/test/a")); - assertQuery("select [jcr:path] from [nt:base] where [propa] < 20", asList("/test/a")); - assertQuery("select [jcr:path] from [nt:base] where [propa] = 20 or [propa] = 10 ", asList("/test/b", "/test/a")); - assertQuery("select [jcr:path] from [nt:base] where [propa] > 10 and [propa] < 30", asList("/test/b")); - assertQuery("select [jcr:path] from [nt:base] where [propa] in (10,20)", asList("/test/b", "/test/a")); - assertQuery("select [jcr:path] from [nt:base] where propa is not null", asList("/test/a", "/test/b", "/test/c")); + assertQuery("select [jcr:path] from [nt:base] where [propa] >= 20", List.of("/test/b", "/test/c")); + assertQuery("select [jcr:path] from [nt:base] where [propa] >= 20", List.of("/test/b", "/test/c")); + assertQuery("select [jcr:path] from [nt:base] where [propa] = 20", List.of("/test/b")); + assertQuery("select [jcr:path] from [nt:base] where [propa] <= 20", List.of("/test/b", "/test/a")); + assertQuery("select [jcr:path] from [nt:base] where [propa] < 20", List.of("/test/a")); + assertQuery("select [jcr:path] from [nt:base] where [propa] = 20 or [propa] = 10 ", List.of("/test/b", "/test/a")); + assertQuery("select [jcr:path] from [nt:base] where [propa] > 10 and [propa] < 30", List.of("/test/b")); + assertQuery("select [jcr:path] from [nt:base] where [propa] in (10,20)", List.of("/test/b", "/test/a")); + assertQuery("select [jcr:path] from [nt:base] where propa is not null", List.of("/test/a", "/test/b", "/test/c")); } @Test @@ -704,7 +630,7 @@ public void pathInclude() throws Exception{ assertThat(explain("select [jcr:path] from [nt:base] where [propa] = 10"), containsString("lucene:test1")); - assertQuery("select [jcr:path] from [nt:base] where [propa] = 10", asList("/test/a", "/test/a/b")); + assertQuery("select [jcr:path] from [nt:base] where [propa] = 10", List.of("/test/a", "/test/a/b")); } //OAK-4517 @@ -723,7 +649,7 @@ public void pathIncludeSubrootIndex() throws Exception { String query = "select [jcr:path] from [nt:base] where [propa] = 10 AND ISDESCENDANTNODE('/test')"; assertThat(explain(query), containsString("lucene:test1")); - assertQuery(query, asList("/test/a", "/test/a/b")); + assertQuery(query, List.of("/test/a", "/test/a/b")); } //OAK-4517 @@ -744,12 +670,12 @@ public void pathQuerySubrootIndex() throws Exception { String query = "select [jcr:path] from [nt:base] where [propa] = 10 AND ISDESCENDANTNODE('/test/a')"; String explanation = explain(query); assertThat(explanation, containsString("lucene:test1")); - assertQuery(query, asList("/test/a/b", "/test/a/b/c")); + assertQuery(query, List.of("/test/a/b", "/test/a/b/c")); query = "select [jcr:path] from [nt:base] where [propa] = 10 AND ISDESCENDANTNODE('/test/a/b')"; explanation = explain(query); assertThat(explanation, containsString("lucene:test1")); - assertQuery(query, asList("/test/a/b/c")); + assertQuery(query, List.of("/test/a/b/c")); query = "select [jcr:path] from [nt:base] where [propa] = 10 AND ISDESCENDANTNODE('/test')"; explanation = explain(query); @@ -779,7 +705,7 @@ public void pathExcludeSubrootIndex() throws Exception{ String query = "select [jcr:path] from [nt:base] where [propa] = 10 AND ISDESCENDANTNODE('/test')"; assertThat(explain(query), containsString("lucene:test1")); - assertQuery(query, asList("/test/c")); + assertQuery(query, List.of("/test/c")); //Make some change and then check subTreeRoot = root.getTree("/").getChild("test"); @@ -787,7 +713,7 @@ public void pathExcludeSubrootIndex() throws Exception{ subTreeRoot.addChild("f").setProperty("propa", 10); root.commit(); - assertQuery(query, asList("/test/c", "/test/f")); + assertQuery(query, List.of("/test/c", "/test/f")); } @Test @@ -806,16 +732,15 @@ public void determinePropTypeFromRestriction() throws Exception{ assertThat(explain("select [jcr:path] from [nt:base] where [propa] >= 20"), containsString("lucene:test1")); - assertQuery("select [jcr:path] from [nt:base] where [propa] >= 20", asList("/test/b", "/test/c")); - assertQuery("select [jcr:path] from [nt:base] where [propa] >= 20", asList("/test/b", "/test/c")); - assertQuery("select [jcr:path] from [nt:base] where [propa] = 20", asList("/test/b")); - assertQuery("select [jcr:path] from [nt:base] where [propa] <= 20", asList("/test/b", "/test/a")); - assertQuery("select [jcr:path] from [nt:base] where [propa] < 20", asList("/test/a")); - assertQuery("select [jcr:path] from [nt:base] where [propa] = 20 or [propa] = 10 ", asList("/test/b", "/test/a")); - assertQuery("select [jcr:path] from [nt:base] where [propa] > 10 and [propa] < 30", asList("/test/b")); - assertQuery("select [jcr:path] from [nt:base] where [propa] in (10,20)", asList("/test/b", "/test/a")); - assertQuery("select [jcr:path] from [nt:base] where propa is not null", asList("/test/a", "/test/b", "/test/c")); - + assertQuery("select [jcr:path] from [nt:base] where [propa] >= 20", List.of("/test/b", "/test/c")); + assertQuery("select [jcr:path] from [nt:base] where [propa] >= 20", List.of("/test/b", "/test/c")); + assertQuery("select [jcr:path] from [nt:base] where [propa] = 20", List.of("/test/b")); + assertQuery("select [jcr:path] from [nt:base] where [propa] <= 20", List.of("/test/b", "/test/a")); + assertQuery("select [jcr:path] from [nt:base] where [propa] < 20", List.of("/test/a")); + assertQuery("select [jcr:path] from [nt:base] where [propa] = 20 or [propa] = 10 ", List.of("/test/b", "/test/a")); + assertQuery("select [jcr:path] from [nt:base] where [propa] > 10 and [propa] < 30", List.of("/test/b")); + assertQuery("select [jcr:path] from [nt:base] where [propa] in (10,20)", List.of("/test/b", "/test/a")); + assertQuery("select [jcr:path] from [nt:base] where propa is not null", List.of("/test/a", "/test/b", "/test/c")); } @Test @@ -833,12 +758,12 @@ public void rangeQueriesWithDouble() throws Exception { test.addChild("d").setProperty("propb", "foo"); root.commit(); - assertQuery("select [jcr:path] from [nt:base] where [propa] >= 20.3", asList("/test/b", "/test/c")); - assertQuery("select [jcr:path] from [nt:base] where [propa] = 20.4", asList("/test/b")); - assertQuery("select [jcr:path] from [nt:base] where [propa] <= 20.5", asList("/test/b", "/test/a")); - assertQuery("select [jcr:path] from [nt:base] where [propa] < 20.4", asList("/test/a")); - assertQuery("select [jcr:path] from [nt:base] where [propa] > 10.5 and [propa] < 30", asList("/test/b")); - assertQuery("select [jcr:path] from [nt:base] where propa is not null", asList("/test/a", "/test/b", "/test/c")); + assertQuery("select [jcr:path] from [nt:base] where [propa] >= 20.3", List.of("/test/b", "/test/c")); + assertQuery("select [jcr:path] from [nt:base] where [propa] = 20.4", List.of("/test/b")); + assertQuery("select [jcr:path] from [nt:base] where [propa] <= 20.5", List.of("/test/b", "/test/a")); + assertQuery("select [jcr:path] from [nt:base] where [propa] < 20.4", List.of("/test/a")); + assertQuery("select [jcr:path] from [nt:base] where [propa] > 10.5 and [propa] < 30", List.of("/test/b")); + assertQuery("select [jcr:path] from [nt:base] where propa is not null", List.of("/test/a", "/test/b", "/test/c")); } @Test @@ -856,15 +781,15 @@ public void rangeQueriesWithString() throws Exception { test.addChild("e").setProperty("propb", "g"); root.commit(); - assertQuery("select [jcr:path] from [nt:base] where propa = 'a'", asList("/test/a")); + assertQuery("select [jcr:path] from [nt:base] where propa = 'a'", List.of("/test/a")); //Check that string props are not tokenized - assertQuery("select [jcr:path] from [nt:base] where propa = 'b is b'", asList("/test/b")); - assertQuery("select [jcr:path] from [nt:base] where propa in ('a', 'c')", asList("/test/a", "/test/c")); - assertQuery("select [jcr:path] from [nt:base] where [propb] >= 'f'", asList("/test/d", "/test/e")); - assertQuery("select [jcr:path] from [nt:base] where [propb] <= 'f'", asList("/test/c", "/test/d")); - assertQuery("select [jcr:path] from [nt:base] where [propb] > 'e'", asList("/test/d", "/test/e")); - assertQuery("select [jcr:path] from [nt:base] where [propb] < 'g'", asList("/test/c", "/test/d")); - assertQuery("select [jcr:path] from [nt:base] where propa is not null", asList("/test/a", "/test/b", "/test/c")); + assertQuery("select [jcr:path] from [nt:base] where propa = 'b is b'", List.of("/test/b")); + assertQuery("select [jcr:path] from [nt:base] where propa in ('a', 'c')", List.of("/test/a", "/test/c")); + assertQuery("select [jcr:path] from [nt:base] where [propb] >= 'f'", List.of("/test/d", "/test/e")); + assertQuery("select [jcr:path] from [nt:base] where [propb] <= 'f'", List.of("/test/c", "/test/d")); + assertQuery("select [jcr:path] from [nt:base] where [propb] > 'e'", List.of("/test/d", "/test/e")); + assertQuery("select [jcr:path] from [nt:base] where [propb] < 'g'", List.of("/test/c", "/test/d")); + assertQuery("select [jcr:path] from [nt:base] where propa is not null", List.of("/test/a", "/test/b", "/test/c")); } @Test @@ -882,11 +807,11 @@ public void rangeQueriesWithDate() throws Exception { test.addChild("d").setProperty("propb", "foo"); root.commit(); - assertQuery("select [jcr:path] from [nt:base] where [propa] >= " + dt("15/02/2014"), asList("/test/b", "/test/c")); - assertQuery("select [jcr:path] from [nt:base] where [propa] <=" + dt("15/03/2014"), asList("/test/b", "/test/a")); - assertQuery("select [jcr:path] from [nt:base] where [propa] < " + dt("14/03/2014"), asList("/test/a")); - assertQuery("select [jcr:path] from [nt:base] where [propa] > "+ dt("15/02/2014") + " and [propa] < " + dt("13/04/2014"), asList("/test/b")); - assertQuery("select [jcr:path] from [nt:base] where propa is not null", asList("/test/a", "/test/b", "/test/c")); + assertQuery("select [jcr:path] from [nt:base] where [propa] >= " + dt("15/02/2014"), List.of("/test/b", "/test/c")); + assertQuery("select [jcr:path] from [nt:base] where [propa] <=" + dt("15/03/2014"), List.of("/test/b", "/test/a")); + assertQuery("select [jcr:path] from [nt:base] where [propa] < " + dt("14/03/2014"), List.of("/test/a")); + assertQuery("select [jcr:path] from [nt:base] where [propa] > "+ dt("15/02/2014") + " and [propa] < " + dt("13/04/2014"), List.of("/test/b")); + assertQuery("select [jcr:path] from [nt:base] where propa is not null", List.of("/test/a", "/test/b", "/test/c")); } @Test @@ -903,7 +828,7 @@ public void nativeQueries() throws Exception { root.commit(); assertQuery("select [jcr:path] from [nt:base] where native('foo', 'propa:(humpty OR dumpty)')", - asList("/test/a", "/test/b")); + List.of("/test/a", "/test/b")); } @Test @@ -916,7 +841,7 @@ public void testWithRelativeProperty() throws Exception{ test.addChild("a").addChild("b").setProperty("propa", "a"); root.commit(); - assertQuery("select [jcr:path] from [nt:base] as s where [b/propa] = 'a'", asList("/test2/a")); + assertQuery("select [jcr:path] from [nt:base] as s where [b/propa] = 'a'", List.of("/test2/a")); } @@ -932,7 +857,7 @@ public void indexDefinitionBelowRoot() throws Exception { test.addChild("a").setProperty("propa", "a"); root.commit(); - assertQuery("select [jcr:path] from [nt:base] as s where ISDESCENDANTNODE(s, '/test') and propa = 'a'", asList("/test/test2/a")); + assertQuery("select [jcr:path] from [nt:base] as s where ISDESCENDANTNODE(s, '/test') and propa = 'a'", List.of("/test/test2/a")); } @Test @@ -948,7 +873,7 @@ public void indexDefinitionBelowRoot2() throws Exception { root.commit(); assertQuery("select [jcr:path] from [nt:base] as s where ISDESCENDANTNODE(s, '/test/test2') and propa = 'a'", - asList("/test/test2/test3/a")); + List.of("/test/test2/test3/a")); } @Test @@ -963,7 +888,7 @@ public void indexDefinitionBelowRoot3() throws Exception { root.commit(); //asert that (1) result gets returned correctly, (2) parent isn't there, and (3) child is returned - assertQuery("select [jcr:path] from [nt:base] as s where ISDESCENDANTNODE(s, '/test') and propa = 'a'", asList("/test/test1")); + assertQuery("select [jcr:path] from [nt:base] as s where ISDESCENDANTNODE(s, '/test') and propa = 'a'", List.of("/test/test1")); } @Test @@ -988,28 +913,28 @@ public void queryPathRescrictionWithoutEvaluatePathRestriction() throws Exceptio queryIndexProvider.setShouldCount(true); // Top level index - assertQuery("/jcr:root/test/a/c/d[@propa='a']", XPATH, asList("/test/a/c/d")); + assertQuery("/jcr:root/test/a/c/d[@propa='a']", XPATH, List.of("/test/a/c/d")); assertEquals("Unexpected number of docs passed back to query engine", 1, queryIndexProvider.getCount()); queryIndexProvider.reset(); - assertQuery("/jcr:root/test/a/c/*[@propa='a']", XPATH, asList("/test/a/c/d")); + assertQuery("/jcr:root/test/a/c/*[@propa='a']", XPATH, List.of("/test/a/c/d")); assertEquals("Unexpected number of docs passed back to query engine", 1, queryIndexProvider.getCount()); queryIndexProvider.reset(); - assertQuery("/jcr:root/test/a//*[@propa='a']", XPATH, asList("/test/a/c/d")); + assertQuery("/jcr:root/test/a//*[@propa='a']", XPATH, List.of("/test/a/c/d")); assertEquals("Unexpected number of docs passed back to query engine", 1, queryIndexProvider.getCount()); queryIndexProvider.reset(); // Sub-root index - assertQuery("/jcr:root/subRoot/test/a/c/d[@propa='a']", XPATH, asList("/subRoot/test/a/c/d")); + assertQuery("/jcr:root/subRoot/test/a/c/d[@propa='a']", XPATH, List.of("/subRoot/test/a/c/d")); assertEquals("Unexpected number of docs passed back to query engine", 1, queryIndexProvider.getCount()); queryIndexProvider.reset(); - assertQuery("/jcr:root/subRoot/test/a/c/*[@propa='a']", XPATH, asList("/subRoot/test/a/c/d")); + assertQuery("/jcr:root/subRoot/test/a/c/*[@propa='a']", XPATH, List.of("/subRoot/test/a/c/d")); assertEquals("Unexpected number of docs passed back to query engine", 1, queryIndexProvider.getCount()); queryIndexProvider.reset(); - assertQuery("/jcr:root/subRoot/test/a//*[@propa='a']", XPATH, asList("/subRoot/test/a/c/d")); + assertQuery("/jcr:root/subRoot/test/a//*[@propa='a']", XPATH, List.of("/subRoot/test/a/c/d")); assertEquals("Unexpected number of docs passed back to query engine", 1, queryIndexProvider.getCount()); queryIndexProvider.reset(); } @@ -1038,7 +963,7 @@ public void sortQueriesWithLong_OrderedProps() throws Exception { @Test public void sortQueriesWithLong_NotIndexed() throws Exception { - Tree idx = createIndex("test1", Collections.emptySet()); + Tree idx = createIndex("test1", Set.of()); idx.setProperty(createProperty(ORDERED_PROP_NAMES, Set.of("foo"), STRINGS)); Tree propIdx = idx.addChild(PROP_NODE).addChild("foo"); propIdx.setProperty(PROP_TYPE, PropertyType.TYPENAME_LONG); @@ -1056,7 +981,7 @@ public void sortQueriesWithLong_NotIndexed() throws Exception { @Test public void sortQueriesWithLong_NotIndexed_relativeProps() throws Exception { - Tree idx = createIndex("test1", Collections.emptySet()); + Tree idx = createIndex("test1", Set.of()); idx.setProperty(createProperty(ORDERED_PROP_NAMES, Set.of("foo/bar"), STRINGS)); Tree propIdx = idx.addChild(PROP_NODE).addChild("foo").addChild("bar"); propIdx.setProperty(PROP_TYPE, PropertyType.TYPENAME_LONG); @@ -1339,7 +1264,7 @@ public void indexTimeFieldBoost() throws Exception { String queryString = "//* [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/c", "/test/a", "/test/b"), XPATH, true); + assertOrderedQuery(queryString, List.of("/test/c", "/test/a", "/test/b"), XPATH, true); } @Test @@ -1390,7 +1315,7 @@ public void boostTitleOverDescription() throws Exception{ assertThat(explain, containsString("full:jcr:content/jcr:description:batman^2.0")); assertThat(explain, containsString(":fulltext:batman")); - assertOrderedQuery(queryString, asList("/test/a", "/test/b", "/test/c"), XPATH, true); + assertOrderedQuery(queryString, List.of("/test/a", "/test/b", "/test/c"), XPATH, true); } @Test @@ -1468,7 +1393,7 @@ private void fulltextBooleanComplexOrQueries(boolean ver2) throws Exception { assertQuery( "select * from [nt:base] where CONTAINS(*, 'fox') and CONTAINS([propb], '\"winter is here\" OR \"summer " + "is here\"')", - asList("/test/a", "/test/b")); + List.of("/test/a", "/test/b")); } // OAK-2434 @@ -1500,7 +1425,7 @@ public void luceneAndExclude() throws Exception { String sql = "SELECT * FROM [nt:base] WHERE [jcr:path] LIKE \'" + r.getPath() + "/%\'" + " AND CONTAINS(*, \'text \'\'fox jumps\'\' -other\')"; - assertQuery(sql, asList("/test/node1")); + assertQuery(sql, List.of("/test/node1")); } private String measureWithLimit(String query, String lang, int limit) throws ParseException { @@ -1538,7 +1463,7 @@ public void indexTimeFieldBoostAndRelativeProperty() throws Exception { 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); + assertOrderedQuery(queryString, List.of("/test/b", "/test/c", "/test/a"), XPATH, true); } @Test @@ -1551,8 +1476,8 @@ public void customTikaConfig() throws Exception{ createFileNode(test, "xml", "sky is blue", "application/xml"); root.commit(); - assertQuery("select * from [nt:base] where CONTAINS(*, 'fox ')", asList("/test/text/jcr:content")); - assertQuery("select * from [nt:base] where CONTAINS(*, 'sky ')", asList("/test/xml/jcr:content")); + assertQuery("select * from [nt:base] where CONTAINS(*, 'fox ')", List.of("/test/text/jcr:content")); + assertQuery("select * from [nt:base] where CONTAINS(*, 'sky ')", List.of("/test/xml/jcr:content")); //Now disable extraction for application/xml and see that query //does not return any result for that @@ -1577,8 +1502,8 @@ public void customTikaConfig() throws Exception{ idx.setProperty(IndexConstants.REINDEX_PROPERTY_NAME, true); root.commit(); - assertQuery("select * from [nt:base] where CONTAINS(*, 'fox ')", asList("/test/text/jcr:content")); - assertQuery("select * from [nt:base] where CONTAINS(*, 'sky ')", Collections.emptyList()); + assertQuery("select * from [nt:base] where CONTAINS(*, 'fox ')", List.of("/test/text/jcr:content")); + assertQuery("select * from [nt:base] where CONTAINS(*, 'sky ')", List.of()); } @Test @@ -1616,7 +1541,7 @@ public void preExtractedTextProvider() throws Exception{ //As its not a reindex case actual blob content would be accessed assertTrue(testBlob.isStreamAccessed()); - assertQuery("select * from [nt:base] where CONTAINS(*, 'fox ')", asList("/test/text/jcr:content")); + assertQuery("select * from [nt:base] where CONTAINS(*, 'fox ')", List.of("/test/text/jcr:content")); assertEquals(0, textProvider.accessCount); testBlob.resetState(); @@ -1628,7 +1553,7 @@ public void preExtractedTextProvider() throws Exception{ //Now the content should be provided by the PreExtractedTextProvider //and instead of fox its lion! assertFalse(testBlob.isStreamAccessed()); - assertQuery("select * from [nt:base] where CONTAINS(*, 'lion ')", asList("/test/text/jcr:content")); + assertQuery("select * from [nt:base] where CONTAINS(*, 'lion ')", List.of("/test/text/jcr:content")); assertEquals(1, textProvider.accessCount); } @@ -1694,14 +1619,14 @@ public void maxFieldLengthCheck() throws Exception{ test.setProperty("text", "red brown fox was jumping"); root.commit(); - assertQuery("select * from [nt:base] where CONTAINS(*, 'jumping')", asList("/test")); + assertQuery("select * from [nt:base] where CONTAINS(*, 'jumping')", List.of("/test")); idx = root.getTree("/oak:index/test"); idx.setProperty(LuceneIndexConstants.MAX_FIELD_LENGTH, 2); idx.setProperty(IndexConstants.REINDEX_PROPERTY_NAME, true); root.commit(); - assertQuery("select * from [nt:base] where CONTAINS(*, 'jumping')", Collections.emptyList()); + assertQuery("select * from [nt:base] where CONTAINS(*, 'jumping')", List.of()); } @Test @@ -1713,16 +1638,16 @@ public void maxExtractLengthCheck() throws Exception{ createFileNode(test, "text", "red brown fox was jumping", "text/plain"); root.commit(); - assertQuery("select * from [nt:base] where CONTAINS(*, 'jumping')", asList("/test/text/jcr:content")); - assertQuery("select * from [nt:base] where CONTAINS(*, 'red')", asList("/test/text/jcr:content")); + assertQuery("select * from [nt:base] where CONTAINS(*, 'jumping')", List.of("/test/text/jcr:content")); + assertQuery("select * from [nt:base] where CONTAINS(*, 'red')", List.of("/test/text/jcr:content")); idx = root.getTree("/oak:index/test"); idx.addChild(TIKA).setProperty(LuceneIndexConstants.TIKA_MAX_EXTRACT_LENGTH, 15); idx.setProperty(IndexConstants.REINDEX_PROPERTY_NAME, true); root.commit(); - assertQuery("select * from [nt:base] where CONTAINS(*, 'jumping')", Collections.emptyList()); - assertQuery("select * from [nt:base] where CONTAINS(*, 'red')", asList("/test/text/jcr:content")); + assertQuery("select * from [nt:base] where CONTAINS(*, 'jumping')", List.of()); + assertQuery("select * from [nt:base] where CONTAINS(*, 'red')", List.of("/test/text/jcr:content")); } @Test @@ -1734,12 +1659,12 @@ public void binaryNotIndexedWhenMimeTypeNull() throws Exception{ String path = createFileNode(test, "text", "red brown fox was jumping", "text/plain").getPath(); root.commit(); - assertQuery("select * from [nt:base] where CONTAINS(*, 'jumping')", asList("/test/text/jcr:content")); + assertQuery("select * from [nt:base] where CONTAINS(*, 'jumping')", List.of("/test/text/jcr:content")); //Remove the mimeType property. Then binary would not be indexed and result would be empty root.getTree(path).removeProperty(JcrConstants.JCR_MIMETYPE); root.commit(); - assertQuery("select * from [nt:base] where CONTAINS(*, 'jumping')", Collections.emptyList()); + assertQuery("select * from [nt:base] where CONTAINS(*, 'jumping')", List.of()); } @Test @@ -1751,11 +1676,11 @@ public void binaryNotIndexedWhenNotSupportedMimeType() throws Exception{ String path = createFileNode(test, "text", "red brown fox was jumping", "text/plain").getPath(); root.commit(); - assertQuery("select * from [nt:base] where CONTAINS(*, 'jumping')", asList("/test/text/jcr:content")); + assertQuery("select * from [nt:base] where CONTAINS(*, 'jumping')", List.of("/test/text/jcr:content")); root.getTree(path).setProperty(JcrConstants.JCR_MIMETYPE, "foo/bar"); root.commit(); - assertQuery("select * from [nt:base] where CONTAINS(*, 'jumping')", Collections.emptyList()); + assertQuery("select * from [nt:base] where CONTAINS(*, 'jumping')", List.of()); } @Test @@ -1786,7 +1711,7 @@ public void relativePropertyAndCursor() throws Exception{ String queryString = "/jcr:root//element(*, nt:base)[jcr:contains(jcr:content, 'foo' )]"; - assertQuery(queryString, "xpath", asList("/test/b")); + assertQuery(queryString, "xpath", List.of("/test/b")); } @Test @@ -1868,11 +1793,11 @@ public void unionSortQueries() throws Exception { assertQuery( "/jcr:root//element(*, nt:base)[(@propa = 'a4' or @propb = 'b3')] order by @propd", XPATH, - asList("/test/b3", "/test/a4")); + List.of("/test/b3", "/test/a4")); assertQuery( "/jcr:root//element(*, nt:base)[(@propa = 'a3' or @propb = 'b0' or @propc = 'c2')] order by @propd", XPATH, - asList("/test/b0", "/test/c2", "/test/a3")); + List.of("/test/b0", "/test/c2", "/test/a3")); } @Test @@ -1904,9 +1829,9 @@ public void aggregationAndExcludeProperty() throws Exception { // hello and image would be index by aggregation but // jpg should be exclude as there is a property defn to exclude it - assertQuery("select [jcr:path] from [oak:TestNode] where contains(*, 'hello')", asList("/test/a")); - assertQuery("select [jcr:path] from [oak:TestNode] where contains(*, 'image')", asList("/test/a")); - assertQuery("select [jcr:path] from [oak:TestNode] where contains(*, 'jpg')", Collections.emptyList()); + assertQuery("select [jcr:path] from [oak:TestNode] where contains(*, 'hello')", List.of("/test/a")); + assertQuery("select [jcr:path] from [oak:TestNode] where contains(*, 'image')", List.of("/test/a")); + assertQuery("select [jcr:path] from [oak:TestNode] where contains(*, 'jpg')", List.of()); //Check that property index is being used assertThat(explain("select [jcr:path] from [oak:TestNode] where [original/jcr:content/type] = 'foo'"), @@ -1941,55 +1866,15 @@ public void aggregateAndIncludeRelativePropertyByDefault() throws Exception{ // hello and image would be index by aggregation but // jpg should also be included as it has not been excluded - assertQuery("select [jcr:path] from [oak:TestNode] where contains(*, 'hello')", asList("/test/a")); - assertQuery("select [jcr:path] from [oak:TestNode] where contains(*, 'image')", asList("/test/a")); - assertQuery("select [jcr:path] from [oak:TestNode] where contains(*, 'jpg')", asList("/test/a")); + assertQuery("select [jcr:path] from [oak:TestNode] where contains(*, 'hello')", List.of("/test/a")); + assertQuery("select [jcr:path] from [oak:TestNode] where contains(*, 'image')", List.of("/test/a")); + assertQuery("select [jcr:path] from [oak:TestNode] where contains(*, 'jpg')", List.of("/test/a")); //Check that property index is being used assertThat(explain("select [jcr:path] from [oak:TestNode] where [original/jcr:content/type] = 'foo'"), containsString("original/jcr:content/type:foo")); } - @Test - public void indexingBasedOnMixin() throws Exception { - Tree idx = createIndex("test1", Set.of("propa", "propb")); - Tree props = TestUtil.newRulePropTree(idx, "mix:title"); - Tree prop = props.addChild(TestUtil.unique("prop")); - prop.setProperty(FulltextIndexConstants.PROP_NAME, "jcr:title"); - prop.setProperty(PROP_PROPERTY_INDEX, true); - root.commit(); - - Tree test = root.getTree("/").addChild("test"); - createNodeWithMixinType(test, "a", "mix:title").setProperty("jcr:title", "a"); - createNodeWithMixinType(test, "b", "mix:title").setProperty("jcr:title", "c"); - test.addChild("c").setProperty("jcr:title", "a"); - root.commit(); - - String propabQuery = "select [jcr:path] from [mix:title] where [jcr:title] = 'a'"; - assertThat(explain(propabQuery), containsString("/oak:index/test1")); - assertQuery(propabQuery, asList("/test/a")); - } - - @Test - public void indexingBasedOnMixinWithInheritence() throws Exception { - Tree idx = createIndex("test1", Set.of("propa", "propb")); - Tree props = TestUtil.newRulePropTree(idx, "mix:mimeType"); - Tree prop = props.addChild(TestUtil.unique("prop")); - prop.setProperty(FulltextIndexConstants.PROP_NAME, "jcr:mimeType"); - prop.setProperty(PROP_PROPERTY_INDEX, true); - root.commit(); - - Tree test = root.getTree("/").addChild("test"); - createNodeWithType(test, "a", "nt:resource").setProperty("jcr:mimeType", "a"); - createNodeWithType(test, "b", "nt:resource").setProperty("jcr:mimeType", "c"); - test.addChild("c").setProperty("jcr:mimeType", "a"); - root.commit(); - - String propabQuery = "select [jcr:path] from [mix:mimeType] where [jcr:mimeType] = 'a'"; - assertThat(explain(propabQuery), containsString("/oak:index/test1")); - assertQuery(propabQuery, asList("/test/a")); - } - @Test public void indexingPropertyWithAnalyzeButQueryWithWildcard() throws Exception { Tree index = root.getTree("/"); @@ -2018,14 +1903,14 @@ public void indexingPropertyWithAnalyzeButQueryWithWildcard() throws Exception { query = "/jcr:root/test//*[jcr:contains(@jcr:mimeType, '1234')]"; assertThat(explainXpath(query), containsString("/oak:index/test2")); - assertQuery(query, "xpath", asList("/test/a")); + assertQuery(query, "xpath", List.of("/test/a")); query = "/jcr:root/test//*[jcr:contains(., '1234')]"; assertThat(explainXpath(query), containsString("no-index")); query = "/jcr:root/test//*[@jcr:mimeType = '1234']"; assertThat(explainXpath(query), containsString("/oak:index/test2")); - assertQuery(query, "xpath", asList("/test/a")); + assertQuery(query, "xpath", List.of("/test/a")); } @Ignore("OAK-4042") @@ -2055,41 +1940,10 @@ public void gb18030FulltextSuffixQuery() throws Exception { String query; query = "SELECT * from [nt:base] WHERE CONTAINS([text], '" + searchTerm1 + "*')"; - assertQuery(query, SQL2, asList("/test/a")); + assertQuery(query, SQL2, List.of("/test/a")); query = "SELECT * from [nt:base] WHERE CONTAINS([text], '" + searchTerm2 + "*')"; - assertQuery(query, SQL2, asList("/test/a")); - } - - - @Test - public void indexingBasedOnMixinAndRelativeProps() throws Exception { - Tree idx = createIndex("test1", Set.of("propa", "propb")); - Tree props = TestUtil.newRulePropTree(idx, "mix:title"); - Tree prop1 = props.addChild(TestUtil.unique("prop")); - prop1.setProperty(FulltextIndexConstants.PROP_NAME, "jcr:title"); - prop1.setProperty(PROP_PROPERTY_INDEX, true); - - Tree prop2 = props.addChild(TestUtil.unique("prop")); - prop2.setProperty(FulltextIndexConstants.PROP_NAME, "jcr:content/type"); - prop2.setProperty(PROP_PROPERTY_INDEX, true); - root.commit(); - - Tree test = root.getTree("/").addChild("test"); - Tree a = createNodeWithMixinType(test, "a", "mix:title"); - a.setProperty("jcr:title", "a"); - a.addChild("jcr:content").setProperty("type", "foo-a"); - - Tree c = createNodeWithMixinType(test, "c", "mix:title"); - c.setProperty("jcr:title", "c"); - c.addChild("jcr:content").setProperty("type", "foo-c"); - - test.addChild("c").setProperty("jcr:title", "a"); - root.commit(); - - String propabQuery = "select [jcr:path] from [mix:title] where [jcr:content/type] = 'foo-a'"; - assertThat(explain(propabQuery), containsString("/oak:index/test1")); - assertQuery(propabQuery, asList("/test/a")); + assertQuery(query, SQL2, List.of("/test/a")); } @Test @@ -2170,17 +2024,16 @@ public void fulltextQueryWithSpecialChars() throws Exception{ String propabQuery = "select * from [nt:base] where CONTAINS(tag, " + "'stockphotography:business/business_abstract')"; - assertPlanAndQuery(propabQuery, "/oak:index/test1", asList("/test")); + assertPlanAndQuery(propabQuery, "/oak:index/test1", List.of("/test")); String query2 = "select * from [nt:base] where CONTAINS(tag, 'foo!')"; - assertPlanAndQuery(query2, "/oak:index/test1", asList("/test2")); + assertPlanAndQuery(query2, "/oak:index/test1", List.of("/test2")); String query3 = "select * from [nt:base] where CONTAINS(tag, 'a=b')"; - assertPlanAndQuery(query3, "/oak:index/test1", asList("/test3")); + assertPlanAndQuery(query3, "/oak:index/test1", List.of("/test3")); String query4 = "select * from [nt:base] where CONTAINS(tag, 'c=d=e')"; - assertPlanAndQuery(query4, "/oak:index/test1", asList("/test4")); - + assertPlanAndQuery(query4, "/oak:index/test1", List.of("/test4")); } @Test @@ -2197,7 +2050,7 @@ public void fulltextQueryWithRelativeProperty() throws Exception{ root.commit(); String propabQuery = "select * from [nt:base] where CONTAINS([jcr:content/metadata/comment], 'december')"; - assertPlanAndQuery(propabQuery, "/oak:index/test1", asList("/test")); + assertPlanAndQuery(propabQuery, "/oak:index/test1", List.of("/test")); } @Test @@ -2276,7 +2129,7 @@ public void emptySuggestDictionary() throws Exception{ root.commit(); String query = "select * from [nt:base] where [tag] = 'foo'"; - assertPlanAndQuery(query, "/oak:index/test1", Collections.emptyList()); + assertPlanAndQuery(query, "/oak:index/test1", List.of()); } @Test @@ -2345,8 +2198,8 @@ public void subNodeTypes() throws Exception{ root.commit(); - assertPlanAndQuery("select * from [oak:TestSuperType]", "/oak:index/test1", asList("/a", "/b")); - assertPlanAndQuery("select * from [oak:TestMixA]", "/oak:index/test1", asList("/b", "/c")); + assertPlanAndQuery("select * from [oak:TestSuperType]", "/oak:index/test1", List.of("/a", "/b")); + assertPlanAndQuery("select * from [oak:TestMixA]", "/oak:index/test1", List.of("/b", "/c")); } @Test @@ -2389,8 +2242,8 @@ public void subNodeTypes_nodeTypeIndex() throws Exception{ root.commit(); - assertPlanAndQuery("select * from [oak:TestSuperType]", "/oak:index/test1", asList("/a", "/b")); - assertPlanAndQuery("select * from [oak:TestMixA]", "/oak:index/test1", asList("/b", "/c")); + assertPlanAndQuery("select * from [oak:TestSuperType]", "/oak:index/test1", List.of("/a", "/b")); + assertPlanAndQuery("select * from [oak:TestMixA]", "/oak:index/test1", List.of("/b", "/c")); } @@ -2407,7 +2260,7 @@ public void indexDefinitionModifiedPostReindex() throws Exception{ root.commit(); String query = "select * from [nt:base] where [foo] = 'bar'"; - assertPlanAndQuery(query, "/oak:index/test1", asList("/a")); + assertPlanAndQuery(query, "/oak:index/test1", List.of("/a")); Tree barProp = root.getTree("/oak:index/test1/indexRules/nt:base/properties").addChild("bar"); barProp.setProperty("name", "bar"); @@ -2420,7 +2273,7 @@ public void indexDefinitionModifiedPostReindex() throws Exception{ root.getTree("/oak:index/test1").setProperty(REINDEX_PROPERTY_NAME, true); root.commit(); - assertPlanAndQuery(query, "/oak:index/test1", asList("/b")); + assertPlanAndQuery(query, "/oak:index/test1", List.of("/b")); } @Test @@ -2436,7 +2289,7 @@ public void refreshIndexDefinition() throws Exception{ root.commit(); String query = "select * from [nt:base] where [foo] = 'bar'"; - assertPlanAndQuery(query, "/oak:index/test1", asList("/a")); + assertPlanAndQuery(query, "/oak:index/test1", List.of("/a")); Tree barProp = root.getTree("/oak:index/test1/indexRules/nt:base/properties").addChild("bar"); barProp.setProperty("name", "bar"); @@ -2455,11 +2308,11 @@ public void refreshIndexDefinition() throws Exception{ assertFalse(root.getTree("/oak:index/test1").hasProperty(PROP_REFRESH_DEFN)); //However as reindex was not done query would result in empty set - assertPlanAndQuery(query, "/oak:index/test1", Collections.emptyList()); + assertPlanAndQuery(query, "/oak:index/test1", List.of()); } @Test - public void updateOldIndexDefinition() throws Exception{ + public void updateOldIndexDefinition() throws Exception { IndexDefinitionBuilder idxb = new LuceneIndexDefinitionBuilder().noAsync(); idxb.indexRule("nt:base").property("foo").propertyIndex(); Tree idx = root.getTree("/").getChild("oak:index").addChild("test1"); @@ -2488,7 +2341,7 @@ public void updateOldIndexDefinition() throws Exception{ } @Test - public void disableIndexDefnStorage() throws Exception{ + public void disableIndexDefnStorage() throws Exception { IndexDefinition.setDisableStoredIndexDefinition(true); IndexDefinitionBuilder idxb = new LuceneIndexDefinitionBuilder().noAsync(); @@ -2506,7 +2359,7 @@ public void disableIndexDefnStorage() throws Exception{ } @Test - public void storedIndexDefinitionDiff() throws Exception{ + public void storedIndexDefinitionDiff() throws Exception { IndexDefinitionBuilder idxb = new LuceneIndexDefinitionBuilder().noAsync(); idxb.indexRule("nt:base").property("foo").propertyIndex(); Tree idx = root.getTree("/").getChild("oak:index").addChild("test1"); @@ -2533,7 +2386,7 @@ public void storedIndexDefinitionDiff() throws Exception{ } @Test - public void relativeProperties() throws Exception{ + public void relativeProperties() throws Exception { IndexDefinitionBuilder idxb = new LuceneIndexDefinitionBuilder().noAsync(); idxb.indexRule("nt:base").property("foo").propertyIndex(); @@ -2550,10 +2403,10 @@ public void relativeProperties() throws Exception{ root.commit(); assertPlanAndQuery("select * from [nt:base] where [jcr:content/foo] = 'bar'", - "/oak:index/test1", asList("/a", "/b")); + "/oak:index/test1", List.of("/a", "/b")); assertPlanAndQuery("select * from [nt:base] where [jcr:content/metadata/sub/foo] = 'bar'", - "/oak:index/test1", asList("/d")); + "/oak:index/test1", List.of("/d")); } @Test @@ -3102,49 +2955,49 @@ public void pathTransformationWithWildcardInRelativePathFragment() throws Except // XPaths assertPlanAndQueryXPath("//*[j:c/*/@foo = 'bar']", - "/oak:index/fooIndex", asList("/a", "/b", "/d/e", "/")); + "/oak:index/fooIndex", List.of("/a", "/b", "/d/e", "/")); assertPlanAndQueryXPath("//*[e/j:c/*/@foo = 'bar']", - "/oak:index/fooIndex", asList("/d")); + "/oak:index/fooIndex", List.of("/d")); assertPlanAndQueryXPath("//*[*/*/@foo = 'bar']", - "/oak:index/fooIndex", asList("/a", "/b", "/d/e", "/")); + "/oak:index/fooIndex", List.of("/a", "/b", "/d/e", "/")); assertPlanAndQueryXPath("//*[*/@foo = 'bar']", "/oak:index/fooIndex", - asList("/a/j:c", "/b/j:c", "/c", "/d/e/j:c", "/j:c", "/")); + List.of("/a/j:c", "/b/j:c", "/c", "/d/e/j:c", "/j:c", "/")); assertPlanAndQueryXPath("//*[j:c/*/@foo = 'bar']", - "/oak:index/fooIndex", asList("/a", "/b", "/d/e", "/")); + "/oak:index/fooIndex", List.of("/a", "/b", "/d/e", "/")); assertPlanAndQueryXPath("//*[*/foo1/@foo = 'bar']", - "/oak:index/fooIndex", asList("/a")); + "/oak:index/fooIndex", List.of("/a")); assertPlanAndQueryXPath("//*[*/*/foo3/@foo = 'bar']", - "/oak:index/fooIndex", asList("/d")); + "/oak:index/fooIndex", List.of("/d")); // SQL2s assertPlanAndQuery("SELECT * FROM [nt:base] WHERE [j:c/*/foo] = 'bar'", - "/oak:index/fooIndex", asList("/a", "/b", "/d/e", "/")); + "/oak:index/fooIndex", List.of("/a", "/b", "/d/e", "/")); assertPlanAndQuery("SELECT * FROM [nt:base] WHERE [e/j:c/*/foo] = 'bar'", - "/oak:index/fooIndex", asList("/d")); + "/oak:index/fooIndex", List.of("/d")); assertPlanAndQuery("SELECT * FROM [nt:base] WHERE [*/*/foo] = 'bar'", - "/oak:index/fooIndex", asList("/a", "/b", "/d/e", "/")); + "/oak:index/fooIndex", List.of("/a", "/b", "/d/e", "/")); assertPlanAndQuery("SELECT * FROM [nt:base] WHERE [*/foo] = 'bar'", "/oak:index/fooIndex", - asList("/a/j:c", "/b/j:c", "/c", "/d/e/j:c", "/j:c", "/")); + List.of("/a/j:c", "/b/j:c", "/c", "/d/e/j:c", "/j:c", "/")); assertPlanAndQuery("SELECT * FROM [nt:base] WHERE [j:c/*/foo] = 'bar'", - "/oak:index/fooIndex", asList("/a", "/b", "/d/e", "/")); + "/oak:index/fooIndex", List.of("/a", "/b", "/d/e", "/")); assertPlanAndQuery("SELECT * FROM [nt:base] WHERE [*/foo1/foo] = 'bar'", - "/oak:index/fooIndex", asList("/a")); + "/oak:index/fooIndex", List.of("/a")); assertPlanAndQuery("SELECT * FROM [nt:base] WHERE [*/*/foo3/foo] = 'bar'", - "/oak:index/fooIndex", asList("/d")); + "/oak:index/fooIndex", List.of("/d")); } @Test @@ -3169,35 +3022,35 @@ public void pathTransformationWithEvaluatePathRestriction() throws Exception { // no path restriction assertPlanAndQueryXPath("//*[j:c/@foo = 'bar']", - "/oak:index/fooIndex", asList("/test/a", "/test/c/d")); + "/oak:index/fooIndex", List.of("/test/a", "/test/c/d")); assertPlanAndQueryXPath("//*[*/@foo = 'bar']", - "/oak:index/fooIndex", asList("/test/a", "/test", "/test/c/d")); + "/oak:index/fooIndex", List.of("/test/a", "/test", "/test/c/d")); assertPlanAndQueryXPath("//*[d/*/@foo = 'bar']", - "/oak:index/fooIndex", asList("/test/c")); + "/oak:index/fooIndex", List.of("/test/c")); // any descendant assertPlanAndQueryXPath("/jcr:root/test//*[j:c/@foo = 'bar']", - "/oak:index/fooIndex", asList("/test/a", "/test/c/d")); + "/oak:index/fooIndex", List.of("/test/a", "/test/c/d")); assertPlanAndQueryXPath("/jcr:root/test//*[*/@foo = 'bar']", - "/oak:index/fooIndex", asList("/test/a", "/test/c/d")); + "/oak:index/fooIndex", List.of("/test/a", "/test/c/d")); assertPlanAndQueryXPath("/jcr:root/test//*[d/*/@foo = 'bar']", - "/oak:index/fooIndex", asList("/test/c")); + "/oak:index/fooIndex", List.of("/test/c")); // direct children assertPlanAndQueryXPath("/jcr:root/test/*[j:c/@foo = 'bar']", - "/oak:index/fooIndex", asList("/test/a")); + "/oak:index/fooIndex", List.of("/test/a")); assertPlanAndQueryXPath("/jcr:root/test/*[*/@foo = 'bar']", - "/oak:index/fooIndex", asList("/test/a")); + "/oak:index/fooIndex", List.of("/test/a")); assertPlanAndQueryXPath("/jcr:root/test/*[d/*/@foo = 'bar']", - "/oak:index/fooIndex", asList("/test/c")); + "/oak:index/fooIndex", List.of("/test/c")); // exact path assertPlanAndQueryXPath("/jcr:root/test/a[j:c/@foo = 'bar']", - "/oak:index/fooIndex", asList("/test/a")); + "/oak:index/fooIndex", List.of("/test/a")); assertPlanAndQueryXPath("/jcr:root/test/a[*/@foo = 'bar']", - "/oak:index/fooIndex", asList("/test/a")); + "/oak:index/fooIndex", List.of("/test/a")); assertPlanAndQueryXPath("/jcr:root/test/c[d/*/@foo = 'bar']", - "/oak:index/fooIndex", asList("/test/c")); + "/oak:index/fooIndex", List.of("/test/c")); } private void assertPlanAndQueryXPath(String query, String planExpectation, List paths) throws ParseException { @@ -3214,7 +3067,7 @@ private void assertPlanAndQuery(String query, String planExpectation, List nodeTypeConstraints(IndexDefinition.IndexingRule PropertyDefinition mixinType = defn.getConfig(JCR_MIXINTYPES); if (mixinType != null && mixinType.propertyIndex) { for (String type : filter.getMixinTypes()) { - queries.add(TermQuery.of(t -> t.field(JCR_MIXINTYPES).value(FieldValue.of(type)))._toQuery()); + queries.add(TermQuery.of(t -> t.field(definition.getElasticKeyword(JCR_MIXINTYPES)).value(FieldValue.of(type)))._toQuery()); } } diff --git a/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexOptions.java b/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexOptions.java index 22d8f844053..4a5cc700add 100644 --- a/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexOptions.java +++ b/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexOptions.java @@ -51,9 +51,12 @@ protected IndexDefinitionBuilder createIndex(IndexDefinitionBuilder builder, Str if (!isAsync) { builder = builder.noAsync(); } - IndexDefinitionBuilder.IndexRule indexRule = builder.indexRule(type); - for (String propName : propNames) { - indexRule.property(propName).propertyIndex(); + + if (type != null) { + IndexDefinitionBuilder.IndexRule indexRule = builder.indexRule(type); + for (String propName : propNames) { + indexRule.property(propName).propertyIndex(); + } } return builder; } diff --git a/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndexCommonTest.java b/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndexCommonTest.java index 099c2cbee50..1d8d24e4788 100644 --- a/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndexCommonTest.java +++ b/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndexCommonTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.plugins.index; -import org.apache.jackrabbit.guava.common.collect.ImmutableList; import org.apache.commons.io.IOUtils; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.oak.api.Result; @@ -30,14 +29,12 @@ import org.junit.Test; import javax.jcr.PropertyType; +import java.nio.charset.StandardCharsets; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.Arrays; import java.util.Calendar; +import java.util.List; -import static java.util.Arrays.asList; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; import static javax.jcr.PropertyType.TYPENAME_DATE; import static org.apache.jackrabbit.oak.api.QueryEngine.NO_BINDINGS; import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.PROPDEF_PROP_NODE_NAME; @@ -77,7 +74,7 @@ public void testBulkProcessorFlushLimit() throws Exception { assertEventually(() -> { assertThat(explain(propaQuery), containsString("/oak:index/test1")); - assertQuery(propaQuery, singletonList("/test/a248")); + assertQuery(propaQuery, List.of("/test/a248")); }); // Now we test for 250 < nodes < 500 @@ -90,7 +87,7 @@ public void testBulkProcessorFlushLimit() throws Exception { assertEventually(() -> { assertThat(explain(propaQuery2), containsString("/oak:index/test1")); - assertQuery(propaQuery2, singletonList("/test/a299")); + assertQuery(propaQuery2, List.of("/test/a299")); }); } @@ -119,9 +116,9 @@ public void indexSelection() throws Exception { assertThat(explain("select [jcr:path] from [nt:base] where [propc] = 'foo'"), containsString("/oak:index/test2")); - assertQuery(propaQuery, Arrays.asList("/test/a", "/test/b")); - assertQuery("select [jcr:path] from [nt:base] where [propa] = 'foo2'", singletonList("/test/c")); - assertQuery("select [jcr:path] from [nt:base] where [propc] = 'foo'", singletonList("/test/d")); + assertQuery(propaQuery, List.of("/test/a", "/test/b")); + assertQuery("select [jcr:path] from [nt:base] where [propa] = 'foo2'", List.of("/test/c")); + assertQuery("select [jcr:path] from [nt:base] where [propc] = 'foo'", List.of("/test/d")); }); } @@ -151,15 +148,15 @@ public void nodeNameViaPropDefinition() throws Exception { String explanation = explain(propabQuery); assertThat(explanation, containsString("/oak:index/test1")); //assertThat(explanation, containsString("{\"term\":{\":nodeName\":{\"value\":\"foo\",")); - assertQuery(propabQuery, singletonList("/test/foo")); + assertQuery(propabQuery, List.of("/test/foo")); - assertQuery(queryPrefix + "LOCALNAME() = 'bar'", singletonList("/test/sc/bar")); - assertQuery(queryPrefix + "LOCALNAME() LIKE 'foo'", singletonList("/test/foo")); - assertQuery(queryPrefix + "LOCALNAME() LIKE 'camel%'", singletonList("/test/camelCase")); + assertQuery(queryPrefix + "LOCALNAME() = 'bar'", List.of("/test/sc/bar")); + assertQuery(queryPrefix + "LOCALNAME() LIKE 'foo'", List.of("/test/foo")); + assertQuery(queryPrefix + "LOCALNAME() LIKE 'camel%'", List.of("/test/camelCase")); - assertQuery(queryPrefix + "NAME() = 'bar'", singletonList("/test/sc/bar")); - assertQuery(queryPrefix + "NAME() LIKE 'foo'", singletonList("/test/foo")); - assertQuery(queryPrefix + "NAME() LIKE 'camel%'", singletonList("/test/camelCase")); + assertQuery(queryPrefix + "NAME() = 'bar'", List.of("/test/sc/bar")); + assertQuery(queryPrefix + "NAME() LIKE 'foo'", List.of("/test/foo")); + assertQuery(queryPrefix + "NAME() LIKE 'camel%'", List.of("/test/camelCase")); }); } @@ -222,12 +219,12 @@ public void propertyExistenceQuery() throws Exception { test.addChild("c").setProperty("propb", "e"); root.commit(); assertEventually(() -> assertQuery("select [jcr:path] from [nt:base] where propa is not null", - Arrays.asList("/test/a", "/test/b"))); + List.of("/test/a", "/test/b"))); } @Test public void propertyExistenceQueryWithNullCheck() throws Exception { - NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType"); + NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE, StandardCharsets.UTF_8), "test nodeType"); Tree idx = indexOptions.setIndex(root, "test1", indexOptions.createIndex(indexOptions.createIndexDefinitionBuilder(), TestUtil.NT_TEST, false, "propa", "propb")); @@ -247,7 +244,7 @@ public void propertyExistenceQueryWithNullCheck() throws Exception { String query = "select [jcr:path] from [oak:TestNode] where [propa] is not null"; String explanation = explain(query); assertThat(explanation, containsString(propertyExistenceQueryWithNullCheckExpectedExplain())); - assertEventually(() -> assertQuery(query, Arrays.asList("/test/a", "/test/b"))); + assertEventually(() -> assertQuery(query, List.of("/test/a", "/test/b"))); } protected String propertyExistenceQueryWithNullCheckExpectedExplain() { @@ -256,7 +253,7 @@ protected String propertyExistenceQueryWithNullCheckExpectedExplain() { @Test public void propertyNonExistenceQuery() throws Exception { - NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType"); + NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE, StandardCharsets.UTF_8), "test nodeType"); Tree idx = indexOptions.setIndex(root, "test1", indexOptions.createIndex(indexOptions.createIndexDefinitionBuilder(), TestUtil.NT_TEST, false, "propa", "propb")); @@ -276,7 +273,7 @@ public void propertyNonExistenceQuery() throws Exception { String query = "select [jcr:path] from [oak:TestNode] where [propa] is null"; String explanation = explain(query); assertThat(explanation, containsString(propertyNonExistenceQueryExpectedExplain())); - assertEventually(() -> assertQuery(query, singletonList("/test/c"))); + assertEventually(() -> assertQuery(query, List.of("/test/c"))); } protected String propertyNonExistenceQueryExpectedExplain() { @@ -306,12 +303,12 @@ public void dateQuery() throws Exception { root.commit(); assertEventually(() -> assertQuery("select [jcr:path] from [nt:base] where date > CAST('2020-12-06T12:32:35.886Z' AS DATE)", - Arrays.asList("/test/a", "/test/b", "/test/c", "/test/d"))); + List.of("/test/a", "/test/b", "/test/c", "/test/d"))); assertEventually(() -> assertQuery("select [jcr:path] from [nt:base] where date > CAST('2020-12-07T12:32:35.886Z' AS DATE) " + "and date < CAST('2020-12-07T20:32:35.886Z' AS DATE)", - Arrays.asList("/test/b", "/test/d"))); + List.of("/test/b", "/test/d"))); assertEventually(() -> assertQuery("select [jcr:path] from [nt:base] where date < CAST('2020-12-07T11:23:33.933-09:00' AS DATE)", - Arrays.asList("/test/a", "/test/b", "/test/d"))); + List.of("/test/a", "/test/b", "/test/d"))); } @Test @@ -330,23 +327,23 @@ public void likeQueriesWithString() throws Exception { root.commit(); assertEventually(() -> assertQuery("select [jcr:path] from [nt:base] where propa like 'hum%'", - ImmutableList.of("/test/a", "/test/c"))); + List.of("/test/a", "/test/c"))); assertQuery("select [jcr:path] from [nt:base] where propa like '%ty'", - ImmutableList.of("/test/a", "/test/b")); + List.of("/test/a", "/test/b")); assertQuery("select [jcr:path] from [nt:base] where propa like '%ump%'", - ImmutableList.of("/test/a", "/test/b", "/test/c")); + List.of("/test/a", "/test/b", "/test/c")); assertQuery("select [jcr:path] from [nt:base] where propa like '_ump%'", - ImmutableList.of("/test/a", "/test/b", "/test/c")); + List.of("/test/a", "/test/b", "/test/c")); assertQuery("select [jcr:path] from [nt:base] where propa like 'a_ice%'", - ImmutableList.of("/test/d")); + List.of("/test/d")); assertQuery("select [jcr:path] from [nt:base] where propa like 'a_i_e%'", - ImmutableList.of("/test/d")); + List.of("/test/d")); assertQuery("select [jcr:path] from [nt:base] where propa like '_____'", - ImmutableList.of("/test/c", "/test/d")); + List.of("/test/c", "/test/d")); assertQuery("select [jcr:path] from [nt:base] where propa like 'h%y'", - ImmutableList.of("/test/a", "/test/c")); + List.of("/test/a", "/test/c")); assertQuery("select [jcr:path] from [nt:base] where propa like 'humpy'", - ImmutableList.of("/test/c")); + List.of("/test/c")); } @Test @@ -370,37 +367,37 @@ public void likeQueriesWithEscapedChars() throws Exception { assertEventually(() -> assertQuery("select [jcr:path] from [nt:base] where propa like 'foo%'", - ImmutableList.of("/test/a", "/test/c", "/test/d", "/test/f", "/test/g", "/test/h", "/test/i")) + List.of("/test/a", "/test/c", "/test/d", "/test/f", "/test/g", "/test/h", "/test/i")) ); assertQuery("select [jcr:path] from [nt:base] where propa like '%oo%'", - ImmutableList.of("/test/a", "/test/c", "/test/d", "/test/e", "/test/f", "/test/g", "/test/h", "/test/i")); + List.of("/test/a", "/test/c", "/test/d", "/test/e", "/test/f", "/test/g", "/test/h", "/test/i")); assertQuery("select [jcr:path] from [nt:base] where propa like 'foo\\%'", - ImmutableList.of("/test/a")); + List.of("/test/a")); assertQuery("select [jcr:path] from [nt:base] where propa like '%oo\\%'", - ImmutableList.of("/test/a")); + List.of("/test/a")); assertQuery("select [jcr:path] from [nt:base] where propa like '%oo\\%%'", - ImmutableList.of("/test/a", "/test/c", "/test/g")); + List.of("/test/a", "/test/c", "/test/g")); assertQuery("select [jcr:path] from [nt:base] where propa like '\\%b%'", - ImmutableList.of("/test/b")); + List.of("/test/b")); assertQuery("select [jcr:path] from [nt:base] where propa like 'foo_'", - ImmutableList.of("/test/a", "/test/d")); + List.of("/test/a", "/test/d")); assertQuery("select [jcr:path] from [nt:base] where propa like '_oo_'", - ImmutableList.of("/test/a", "/test/d")); + List.of("/test/a", "/test/d")); assertQuery("select [jcr:path] from [nt:base] where propa like 'foo\\_'", - ImmutableList.of("/test/d")); + List.of("/test/d")); assertQuery("select [jcr:path] from [nt:base] where propa like '%oo\\_'", - ImmutableList.of("/test/d")); + List.of("/test/d")); assertQuery("select [jcr:path] from [nt:base] where propa like '%oo\\_%'", - ImmutableList.of("/test/d", "/test/f")); + List.of("/test/d", "/test/f")); assertQuery("select [jcr:path] from [nt:base] where propa like '%oo\\%\\_%'", - ImmutableList.of("/test/g")); + List.of("/test/g")); assertQuery("select [jcr:path] from [nt:base] where propa like 'foo\\\\bar'", - ImmutableList.of("/test/h")); + List.of("/test/h")); assertQuery("select [jcr:path] from [nt:base] where propa like '%\\\\%'", - ImmutableList.of("/test/h", "/test/i")); + List.of("/test/h", "/test/i")); assertQuery("select [jcr:path] from [nt:base] where propa like '%\\\\\\%%'", - ImmutableList.of("/test/i")); + List.of("/test/i")); } @Test @@ -421,12 +418,12 @@ public void rangeQueriesWithBeforeEpoch() throws Exception { root.commit(); assertEventually(() -> { - assertQuery("select [jcr:path] from [nt:base] where [propa] >= " + dt("15/02/1768"), asList("/test/b", "/test/c")); - assertQuery("select [jcr:path] from [nt:base] where [propa] <=" + dt("15/03/1769"), asList("/test/b", "/test/a")); - assertQuery("select [jcr:path] from [nt:base] where [propa] < " + dt("14/03/1769"), singletonList("/test/a")); - assertQuery("select [jcr:path] from [nt:base] where [propa] <> " + dt("14/03/1769"), asList("/test/a", "/test/c")); - assertQuery("select [jcr:path] from [nt:base] where [propa] > " + dt("15/02/1768") + " and [propa] < " + dt("13/04/1770"), singletonList("/test/b")); - assertQuery("select [jcr:path] from [nt:base] where propa is not null", asList("/test/a", "/test/b", "/test/c")); + assertQuery("select [jcr:path] from [nt:base] where [propa] >= " + dt("15/02/1768"), List.of("/test/b", "/test/c")); + assertQuery("select [jcr:path] from [nt:base] where [propa] <=" + dt("15/03/1769"), List.of("/test/b", "/test/a")); + assertQuery("select [jcr:path] from [nt:base] where [propa] < " + dt("14/03/1769"), List.of("/test/a")); + assertQuery("select [jcr:path] from [nt:base] where [propa] <> " + dt("14/03/1769"), List.of("/test/a", "/test/c")); + assertQuery("select [jcr:path] from [nt:base] where [propa] > " + dt("15/02/1768") + " and [propa] < " + dt("13/04/1770"), List.of("/test/b")); + assertQuery("select [jcr:path] from [nt:base] where propa is not null", List.of("/test/a", "/test/b", "/test/c")); }); } @@ -454,7 +451,7 @@ public void dateQueryWithEmptyValue() throws Exception { content.setProperty("imageLaunchDate", "", Type.STRING); root.commit(); - assertEventually(() -> assertQuery("select [jcr:path] from [nt:base] where [textField] = 'foo'", singletonList("/test/a"))); + assertEventually(() -> assertQuery("select [jcr:path] from [nt:base] where [textField] = 'foo'", List.of("/test/a"))); } @Test @@ -473,12 +470,83 @@ public void inQueryWithUnparseableValue() throws Exception { root.commit(); assertEventually(() -> { - assertQuery("select [jcr:path] from [nt:base] where [booleanField] in('true', 'True')", singletonList("/test/a")); - assertQuery("select [jcr:path] from [nt:base] where [booleanField] in('true', 'InvalidBool')", singletonList("/test/a")); - assertQuery("select [jcr:path] from [nt:base] where [booleanField] in('foo', 'InvalidBool')", emptyList()); + assertQuery("select [jcr:path] from [nt:base] where [booleanField] in('true', 'True')", List.of("/test/a")); + assertQuery("select [jcr:path] from [nt:base] where [booleanField] in('true', 'InvalidBool')", List.of("/test/a")); + assertQuery("select [jcr:path] from [nt:base] where [booleanField] in('foo', 'InvalidBool')", List.of()); }); } + @Test + public void indexingBasedOnMixin() throws Exception { + indexOptions.setIndex( + root, + "test1", + indexOptions.createIndex(indexOptions.createIndexDefinitionBuilder(), "mix:title", false, "jcr:title") + ); + root.commit(); + + Tree test = root.getTree("/").addChild("test"); + createNodeWithMixinType(test, "a", "mix:title").setProperty("jcr:title", "a"); + createNodeWithMixinType(test, "b", "mix:title").setProperty("jcr:title", "c"); + test.addChild("c").setProperty("jcr:title", "a"); + root.commit(); + + String propabQuery = "select [jcr:path] from [mix:title] where [jcr:title] = 'a'"; + assertEventually(() -> { + assertThat(explain(propabQuery), containsString("/oak:index/test1")); + assertQuery(propabQuery, List.of("/test/a")); + }); + } + + @Test + public void indexingBasedOnMixinWithInheritance() throws Exception { + indexOptions.setIndex( + root, + "test1", + indexOptions.createIndex(indexOptions.createIndexDefinitionBuilder(), "mix:mimeType", false, "jcr:mimeType") + ); + root.commit(); + + Tree test = root.getTree("/").addChild("test"); + createNodeWithType(test, "a", "nt:resource").setProperty("jcr:mimeType", "a"); + createNodeWithType(test, "b", "nt:resource").setProperty("jcr:mimeType", "c"); + test.addChild("c").setProperty("jcr:mimeType", "a"); + root.commit(); + + String propabQuery = "select [jcr:path] from [mix:mimeType] where [jcr:mimeType] = 'a'"; + assertEventually(() -> { + assertThat(explain(propabQuery), containsString("/oak:index/test1")); + assertQuery(propabQuery, List.of("/test/a")); + }); + } + + @Test + public void indexingBasedOnMixinAndRelativeProps() throws Exception { + indexOptions.setIndex( + root, + "test1", + indexOptions.createIndex(indexOptions.createIndexDefinitionBuilder(), "mix:title", false, "jcr:title", "jcr:content/type") + ); + root.commit(); + + Tree test = root.getTree("/").addChild("test"); + Tree a = createNodeWithMixinType(test, "a", "mix:title"); + a.setProperty("jcr:title", "a"); + a.addChild("jcr:content").setProperty("type", "foo-a"); + + Tree c = createNodeWithMixinType(test, "c", "mix:title"); + c.setProperty("jcr:title", "c"); + c.addChild("jcr:content").setProperty("type", "foo-c"); + + test.addChild("c").setProperty("jcr:title", "a"); + root.commit(); + + String propabQuery = "select [jcr:path] from [mix:title] where [jcr:content/type] = 'foo-a'"; + assertEventually(() -> { + assertThat(explain(propabQuery), containsString("/oak:index/test1")); + assertQuery(propabQuery, List.of("/test/a")); + }); + } protected String explain(String query) { String explain = "explain " + query; @@ -505,4 +573,10 @@ private static String dt(String date) { throw new RuntimeException(e); } } + + private static Tree createNodeWithMixinType(Tree t, String nodeName, String typeName){ + t = t.addChild(nodeName); + t.setProperty(JcrConstants.JCR_MIXINTYPES, List.of(typeName), Type.NAMES); + return t; + } }