Author: thomasm
Date: Thu Apr 19 09:03:15 2018
New Revision: 1829519

URL: http://svn.apache.org/viewvc?rev=1829519&view=rev
Log:
OAK-7151 Support indexed based excerpts on properties

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/XPathToSQL2Converter.java
    
jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/XPathToSQL2Converter.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/XPathToSQL2Converter.java?rev=1829519&r1=1829518&r2=1829519&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/XPathToSQL2Converter.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/XPathToSQL2Converter.java
 Thu Apr 19 09:03:15 2018
@@ -232,9 +232,13 @@ public class XPathToSQL2Converter {
                     } else if ("rep:excerpt".equals(identifier)) {
                         Expression.Property p;
 
-                        if (readIf(".")) {
+                        if (readIf(")")) {
                             rewindSelector();
                             p = new Expression.Property(currentSelector, 
"rep:excerpt", false);
+                        } else if (readIf(".")) {
+                            rewindSelector();
+                            p = new Expression.Property(currentSelector, 
"rep:excerpt", false);
+                            read(")");
                         } else {
                             // this will also deal with relative properties
                             Expression e = parseExpression();
@@ -246,8 +250,8 @@ public class XPathToSQL2Converter {
                             rewindSelector();
                             p = new Expression.Property(currentSelector,
                                     "rep:excerpt(" + property + ")", false);
+                            read(")");
                         }
-                        read(")");
 
                         statement.addSelectColumn(p);
                     } else {
@@ -272,8 +276,11 @@ public class XPathToSQL2Converter {
                         Expression.Property p;
 
                         read("(");
-                        if (readIf(".")) {
+                        if (readIf(")")) {
+                            p = new Expression.Property(currentSelector, 
"rep:excerpt", false);
+                        } else if (readIf(".")) {
                             p = new Expression.Property(currentSelector, 
"rep:excerpt", false);
+                            read(")");
                         } else {
                             // this will also deal with relative properties
                             Expression e = parseExpression();
@@ -284,8 +291,8 @@ public class XPathToSQL2Converter {
                             String property = prop.getColumnAliasName();
                             p = new Expression.Property(currentSelector,
                                     "rep:excerpt(" + property + ")", false);
+                            read(")");
                         }
-                        read(")");
 
                         statement.addSelectColumn(p);
                     } else if (readIf("rep:spellcheck")) {

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt?rev=1829519&r1=1829518&r2=1829519&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt
 Thu Apr 19 09:03:15 2018
@@ -24,6 +24,57 @@
 # * new tests are typically be added on top, after the syntax docs
 # * use ascii character only
 
+#
+
+xpath2sql /jcr:root//element(*, nt:base)[jcr:contains(., 
'hello')]/rep:excerpt()
+select [jcr:path], [jcr:score], [rep:excerpt]
+  from [nt:base] as a
+  where contains(*, 'hello')
+  and isdescendantnode(a, '/')
+  /* xpath ... */
+
+xpath2sql /jcr:root//element(*, nt:base)[jcr:contains(., 
'hello')]/rep:excerpt(.)
+select [jcr:path], [jcr:score], [rep:excerpt]
+  from [nt:base] as a
+  where contains(*, 'hello')
+  and isdescendantnode(a, '/')
+  /* xpath ... */
+
+xpath2sql /jcr:root//element(*, nt:base)[jcr:contains(., 
'hello')]/rep:excerpt(@jcr:title)
+select [jcr:path], [jcr:score], [rep:excerpt(jcr:title)]
+  from [nt:base] as a
+  where contains(*, 'hello')
+  and isdescendantnode(a, '/')
+  /* xpath ... */
+
+xpath2sql /jcr:root//element(*, nt:base)[jcr:contains(., 
'hello')]/rep:excerpt(par1/@title)
+select [jcr:path], [jcr:score], [rep:excerpt(par1/title)]
+  from [nt:base] as a
+  where contains(*, 'hello')
+  and isdescendantnode(a, '/')
+  /* xpath ... */
+
+xpath2sql /jcr:root//element(*, nt:base)[jcr:contains(., 
'hello')]/(rep:excerpt())
+select [jcr:path], [jcr:score], [rep:excerpt]
+  from [nt:base] as a
+  where contains(*, 'hello')
+  and isdescendantnode(a, '/')
+  /* xpath ... */
+
+xpath2sql /jcr:root//element(*, nt:base)[jcr:contains(., 
'hello')]/(rep:excerpt(.))
+select [jcr:path], [jcr:score], [rep:excerpt]
+  from [nt:base] as a
+  where contains(*, 'hello')
+  and isdescendantnode(a, '/')
+  /* xpath ... */
+
+xpath2sql /jcr:root//element(*, nt:base)[jcr:contains(., 
'hello')]/(rep:excerpt(jcr:content/@jcr:description) | | 
rep:excerpt(@jcr:title) | rep:excerpt(.))
+select [jcr:path], [jcr:score], [rep:excerpt(jcr:content/jcr:description)], 
[rep:excerpt(jcr:title)], [rep:excerpt]
+  from [nt:base] as a
+  where contains(*, 'hello')
+  and isdescendantnode(a, '/')
+  /* xpath ... */
+
 # OAK-7131
 
 xpath2sql /jcr:root/content[@a=1 or @b=2] order by @foo option(traversal ok)


Reply via email to