You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-issues@jackrabbit.apache.org by "Vikas Saurabh (JIRA)" <ji...@apache.org> on 2016/05/07 22:56:12 UTC
[jira] [Comment Edited] (OAK-4351) Non-root lucene index throws
exception if query constraints match root of sub-tree
[ https://issues.apache.org/jira/browse/OAK-4351?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15275013#comment-15275013 ]
Vikas Saurabh edited comment on OAK-4351 at 5/7/16 10:55 PM:
-------------------------------------------------------------
[~chetanm], here's a patch and a test. Can you please review?
{code}
diff --git a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java
index 749756a..a71f6a2 100644
--- a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java
+++ b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java
@@ -1528,6 +1528,8 @@ public class LucenePropertyIndex implements AdvancedQueryIndex, QueryIndex, Nati
String sub = pathRow.getPath();
if (isVirtualRow()) {
return sub;
+ } else if (!"".equals(pathPrefix) && PathUtils.denotesRoot(sub)) {
+ return pathPrefix;
} else if (PathUtils.isAbsolute(sub)) {
return pathPrefix + sub;
} else {
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 f601e27..a1f8e3c 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
@@ -926,6 +926,22 @@ public class LucenePropertyIndexTest extends AbstractQueryTest {
assertQuery("select [jcr:path] from [nt:base] as s where ISDESCENDANTNODE(s, '/test/test2') and propa = 'a'",
asList("/test/test2/test3/a"));
}
+
+ @Test
+ public void indexDefinitionBelowRoot3() throws Exception {
+ Tree parent = root.getTree("/").addChild("test");
+ Tree idx = createIndex(parent, "test1", of("propa"));
+ idx.addChild(PROP_NODE).addChild("propa");
+ root.commit();
+
+ parent.setProperty("propa", "a");
+ parent.addChild("test1").setProperty("propa", "a");
+ 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"));
+ }
+
@Test
public void sortQueriesWithLong() throws Exception {
Tree idx = createIndex("test1", of("foo", "bar"));
{code}
was (Author: catholicon):
[~chetanm], here's a patch and a test. Can you please review?
{code}
diff --git a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java
index 749756a..a71f6a2 100644
--- a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java
+++ b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java
@@ -1528,6 +1528,8 @@ public class LucenePropertyIndex implements AdvancedQueryIndex, QueryIndex, Nati
String sub = pathRow.getPath();
if (isVirtualRow()) {
return sub;
+ } else if (PathUtils.denotesRoot(sub)) {
+ return pathPrefix;
} else if (PathUtils.isAbsolute(sub)) {
return pathPrefix + sub;
} else {
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 f601e27..a1f8e3c 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
@@ -926,6 +926,22 @@ public class LucenePropertyIndexTest extends AbstractQueryTest {
assertQuery("select [jcr:path] from [nt:base] as s where ISDESCENDANTNODE(s, '/test/test2') and propa = 'a'",
asList("/test/test2/test3/a"));
}
+
+ @Test
+ public void indexDefinitionBelowRoot3() throws Exception {
+ Tree parent = root.getTree("/").addChild("test");
+ Tree idx = createIndex(parent, "test1", of("propa"));
+ idx.addChild(PROP_NODE).addChild("propa");
+ root.commit();
+
+ parent.setProperty("propa", "a");
+ parent.addChild("test1").setProperty("propa", "a");
+ 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"));
+ }
+
@Test
public void sortQueriesWithLong() throws Exception {
Tree idx = createIndex("test1", of("foo", "bar"));
{code}
> Non-root lucene index throws exception if query constraints match root of sub-tree
> ----------------------------------------------------------------------------------
>
> Key: OAK-4351
> URL: https://issues.apache.org/jira/browse/OAK-4351
> Project: Jackrabbit Oak
> Issue Type: Bug
> Components: lucene
> Reporter: Vikas Saurabh
> Assignee: Vikas Saurabh
> Priority: Minor
> Fix For: 1.6
>
>
> LucenePropetyIndexProvider returns incorrect (normalized) path for root of sub-tree if index is defined on the sub-tree. e.g.
> {{/jcr:root/test//element(*, nt:base)\[@foo='bar']}} would fail with following defn
> {noformat}
> + /test
> - foo="bar"
> + test1
> - foo="bar"
> + oak:index
> - indexRules/nt:base/properties/foo/propertyIndex="true"
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)