jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r537767 - in /jackrabbit/trunk/jackrabbit-core/src/main: java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java javacc/sql/JCRSQL.jjt
Date Mon, 14 May 2007 10:06:36 GMT
Author: mreutegg
Date: Mon May 14 03:06:35 2007
New Revision: 537767

URL: http://svn.apache.org/viewvc?view=rev&rev=537767
Log:
JCR-906: Introduce similarity function
- add additional argument

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
    jackrabbit/trunk/jackrabbit-core/src/main/javacc/sql/JCRSQL.jjt

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java?view=diff&rev=537767&r1=537766&r2=537767
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
Mon May 14 03:06:35 2007
@@ -50,6 +50,7 @@
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.NameFormat;
 import org.apache.jackrabbit.name.PathFormat;
+import org.apache.jackrabbit.name.MalformedPathException;
 import org.apache.jackrabbit.util.ISO8601;
 import org.apache.jackrabbit.util.XMLChar;
 import org.apache.jackrabbit.util.ISO9075;
@@ -672,20 +673,8 @@
                         + node.getValueType());
         }
 
-        if (node.getOperation() == QueryConstants.OPERATION_SIMILAR) {
-            try {
-                ItemId id = hmgr.resolvePath(session.getQPath(node.getStringValue()));
-                String uuid = "x";
-                if (id != null && id.denotesNode()) {
-                    uuid = ((NodeId) id).getUUID().toString();
-                }
-                return new SimilarityQuery(uuid, analyzer);
-            } catch (Exception e) {
-                exceptions.add(e);
-            }
-        }
-
-        if (node.getRelativePath() == null) {
+        if (node.getRelativePath() == null &&
+                node.getOperation() != QueryConstants.OPERATION_SIMILAR) {
             exceptions.add(new InvalidQueryException("@* not supported in predicate"));
             return data;
         }
@@ -704,6 +693,24 @@
         }, null);
 
         Path relPath = node.getRelativePath();
+        if (node.getOperation() == QueryConstants.OPERATION_SIMILAR) {
+            // this is a bit ugly:
+            // add the name of a dummy property because relPath actually
+            // references a property. whereas the relPath of the similar
+            // operation references a node
+            Path.PathBuilder builder;
+            if (relPath == null) {
+                builder = new Path.PathBuilder();
+            } else {
+                builder = new Path.PathBuilder(relPath);
+            }
+            builder.addLast(QName.JCR_PRIMARYTYPE);
+            try {
+                relPath = builder.getPath();
+            } catch (MalformedPathException e) {
+                // will never happen
+            }
+        }
         String field = "";
         try {
             field = NameFormat.format(relPath.getNameElement().getName(), nsMappings);
@@ -742,7 +749,7 @@
                 }
             } else {
                 // will never match -> create dummy query
-                query = new TermQuery(new Term(FieldNames.UUID, ""));
+                query = new TermQuery(new Term(FieldNames.UUID, "x"));
             }
         } else {
             switch (node.getOperation()) {
@@ -881,6 +888,18 @@
                     break;
                 case QueryConstants.OPERATION_NULL:
                     query = new NotQuery(new MatchAllQuery(field));
+                    break;
+                case QueryConstants.OPERATION_SIMILAR:
+                    String uuid = "x";
+                    try {
+                        ItemId id = hmgr.resolvePath(session.getQPath(node.getStringValue()));
+                        if (id != null && id.denotesNode()) {
+                            uuid = ((NodeId) id).getUUID().toString();
+                        }
+                    } catch (Exception e) {
+                        exceptions.add(e);
+                    }
+                    query = new SimilarityQuery(uuid, analyzer);
                     break;
                 case QueryConstants.OPERATION_NOT_NULL:
                     query = new MatchAllQuery(field);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java?view=diff&rev=537767&r1=537766&r2=537767
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
Mon May 14 03:06:35 2007
@@ -925,18 +925,21 @@
                     exceptions.add(new InvalidQueryException("Unsupported location for fn:upper-case()"));
                 }
             } else if (NameFormat.format(REP_SIMILAR, resolver).equals(fName)) {
-                if (node.jjtGetNumChildren() == 2) {
+                if (node.jjtGetNumChildren() == 3) {
                     if (queryNode instanceof NAryQueryNode) {
                         NAryQueryNode parent = (NAryQueryNode) queryNode;
                         RelationQueryNode rel = new RelationQueryNode(
                                 parent, RelationQueryNode.OPERATION_SIMILAR);
                         parent.addOperand(rel);
-                        // get path string
+                        // assign path
                         node.jjtGetChild(1).jjtAccept(this, rel);
+
+                        // get path string
+                        node.jjtGetChild(2).jjtAccept(this, rel);
                         // check if string is set
                         if (rel.getStringValue() == null) {
                             exceptions.add(new InvalidQueryException(
-                                    "Argument for rep:similar() must be of type string"));
+                                    "Second argument for rep:similar() must be of type string"));
                         }
                     } else {
                         exceptions.add(new InvalidQueryException(

Modified: jackrabbit/trunk/jackrabbit-core/src/main/javacc/sql/JCRSQL.jjt
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/javacc/sql/JCRSQL.jjt?view=diff&rev=537767&r1=537766&r2=537767
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/javacc/sql/JCRSQL.jjt (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/javacc/sql/JCRSQL.jjt Mon May 14 03:06:35 2007
@@ -363,6 +363,8 @@
   |
     (
       <SIMILAR> "(" { jjtThis.setOperationType(QueryConstants.OPERATION_SIMILAR); }
+        ("." | identifier = Identifier() { jjtThis.setIdentifier(identifier); })
+        ","
         value = CharStringLiteral()
           {
             ASTLiteral s = new ASTLiteral(JJTLITERAL);



Mime
View raw message