jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r161751 - in incubator/jackrabbit/trunk/src: java/org/apache/jackrabbit/core/query/lucene/ test/org/apache/jackrabbit/core/query/ test/org/apache/jackrabbit/test/api/query/
Date Mon, 18 Apr 2005 10:44:07 GMT
Author: mreutegg
Date: Mon Apr 18 03:44:02 2005
New Revision: 161751

URL: http://svn.apache.org/viewcvs?view=rev&rev=161751
Log:
Update to spec 0.16.4:
- Selecting jcr:score and jcr:path is not required anymore. jcr:path is always added to the
select list and jcr:score appears as the last column if there is a contains function in the
query statement.

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/query/AbstractQueryTest.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/query/OrderByTest.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPropertyNamesTest.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SQLJcrPathTest.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SQLQueryLevel2Test.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/XPathJcrPathTest.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/XPathQueryLevel2Test.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java?view=diff&r1=161750&r2=161751
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java
Mon Apr 18 03:44:02 2005
@@ -31,6 +31,12 @@
 import org.apache.jackrabbit.core.query.PropertyTypeRegistry;
 import org.apache.jackrabbit.core.query.QueryParser;
 import org.apache.jackrabbit.core.query.QueryRootNode;
+import org.apache.jackrabbit.core.query.OrQueryNode;
+import org.apache.jackrabbit.core.query.AndQueryNode;
+import org.apache.jackrabbit.core.query.NotQueryNode;
+import org.apache.jackrabbit.core.query.TextsearchQueryNode;
+import org.apache.jackrabbit.core.query.PathQueryNode;
+import org.apache.jackrabbit.core.query.QueryConstants;
 import org.apache.jackrabbit.core.security.AccessManager;
 import org.apache.log4j.Logger;
 import org.apache.lucene.search.Hits;
@@ -44,6 +50,7 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Arrays;
 
 /**
  * Implements the {@link ExecutableQuery} interface.
@@ -163,8 +170,9 @@
         }
 
         // get select properties
-        QName[] selectProps = root.getSelectProperties();
-        if (selectProps.length == 0) {
+        List selectProps = new ArrayList();
+        selectProps.addAll(Arrays.asList(root.getSelectProperties()));
+        if (selectProps.size() == 0) {
             // use node type constraint
             LocationStepQueryNode[] steps = root.getLocationNode().getPathSteps();
             final QName[] ntName = new QName[1];
@@ -179,21 +187,64 @@
             }
             NodeTypeImpl nt = session.getNodeTypeManager().getNodeType(ntName[0]);
             PropertyDefinition[] propDefs = nt.getPropertyDefinitions();
-            List tmp = new ArrayList();
             for (int i = 0; i < propDefs.length; i++) {
                 if (!propDefs[i].isMultiple()) {
-                    tmp.add(((PropertyDefinitionImpl) propDefs[i]).getQName());
+                    selectProps.add(((PropertyDefinitionImpl) propDefs[i]).getQName());
                 }
             }
-            selectProps = (QName[]) tmp.toArray(new QName[tmp.size()]);
+        }
+
+        // add jcr:path
+        selectProps.add(QueryConstants.JCR_PATH);
+
+        // add jcr:score if necessary
+        if(hasTextsearchNode(root.getLocationNode())) {
+            selectProps.add(QueryConstants.JCR_SCORE);
         }
 
         // return QueryResult
         return new QueryResultImpl(itemMgr,
                 (String[]) uuids.toArray(new String[uuids.size()]),
                 (Float[]) scores.toArray(new Float[scores.size()]),
-                selectProps,
+                (QName[]) selectProps.toArray(new QName[selectProps.size()]),
                 session.getNamespaceResolver(),
                 orderNode == null);
+    }
+
+    //-----------------------------< internal >---------------------------------
+
+    /**
+     * Returns <code>true</code> if <code>node</code> has a
+     * {@link org.apache.jackrabbit.core.query.TextsearchQueryNode} somewhere
+     * down the query tree; <code>false</code> otherwise.
+     * @param node the path node.
+     * @return <code>true</code> if the query tree contains a textsearch
+     *  node, <code>false</code> otherwise.
+     */
+    private static boolean hasTextsearchNode(PathQueryNode node) {
+        final boolean[] textsearch = new boolean[1];
+        node.acceptOperands(new DefaultQueryNodeVisitor() {
+            public Object visit(OrQueryNode node, Object data) {
+                return node.acceptOperands(this, data);
+            }
+
+            public Object visit(AndQueryNode node, Object data) {
+                return node.acceptOperands(this, data);
+            }
+
+            public Object visit(NotQueryNode node, Object data) {
+                return node.acceptOperands(this, data);
+            }
+
+            public Object visit(TextsearchQueryNode node, Object data) {
+                textsearch[0] = true;
+                return data;
+            }
+
+            public Object visit(LocationStepQueryNode node, Object data) {
+                return node.acceptOperands(this, data);
+            }
+        }, null);
+        return textsearch[0];
     }
 }

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/query/AbstractQueryTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/query/AbstractQueryTest.java?view=diff&r1=161750&r2=161751
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/query/AbstractQueryTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/query/AbstractQueryTest.java
Mon Apr 18 03:44:02 2005
@@ -60,25 +60,25 @@
 
     /**
      * Checks if the <code>result</code> contains a number of <code>hits</code>
-     * and <code>properties</code>.
+     * and <code>columns</code>.
      *
-     * @param result     the <code>QueryResult</code>.
-     * @param hits       the number of expected hits.
-     * @param properties the number of expected properties.
-     * @throws RepositoryException if an error occurs while iterating over
-     *                             the result nodes.
+     * @param result  the <code>QueryResult</code>.
+     * @param hits    the number of expected hits.
+     * @param columns the number of expected columns.
+     * @throws RepositoryException if an error occurs while iterating over the
+     *                             result nodes.
      */
-    protected void checkResult(QueryResult result, int hits, int properties)
+    protected void checkResult(QueryResult result, int hits, int columns)
             throws RepositoryException {
         checkResult(result, hits);
-        // now check property count
+        // now check column count
         int count = 0;
         log.println("Properties:");
         String[] propNames = result.getColumnNames();
-        for (RowIterator it = result.getRows(); it.hasNext();) {
+        for (RowIterator it = result.getRows(); it.hasNext(); count++) {
             StringBuffer msg = new StringBuffer();
             Value[] values = it.nextRow().getValues();
-            for (int i = 0; i < propNames.length; i++, count++) {
+            for (int i = 0; i < propNames.length; i++) {
                 msg.append("  ").append(propNames[i]).append(": ");
                 if (values[i] == null) {
                     msg.append("null");
@@ -91,7 +91,7 @@
         if (count == 0) {
             log.println("  NONE");
         }
-        assertEquals("Wrong property count.", properties, count);
+        assertEquals("Wrong column count.", columns, count);
     }
 
     /**

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/query/OrderByTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/query/OrderByTest.java?view=diff&r1=161750&r2=161751
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/query/OrderByTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/query/OrderByTest.java
Mon Apr 18 03:44:02 2005
@@ -40,7 +40,7 @@
 
         testRootNode.save();
 
-        String sql = "SELECT value, jcr:score FROM nt:unstructured WHERE " +
+        String sql = "SELECT value FROM nt:unstructured WHERE " +
                 "jcr:path LIKE '" + testRoot + "/%' ORDER BY jcr:score, value";
         Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
         QueryResult result = q.execute();

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPropertyNamesTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPropertyNamesTest.java?view=diff&r1=161750&r2=161751
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPropertyNamesTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPropertyNamesTest.java
Mon Apr 18 03:44:02 2005
@@ -80,6 +80,8 @@
                 singleValPropNames.add(pd[i].getName());
             }
         }
+        // add jcr:path
+        singleValPropNames.add(jcrPath);
 
         String[] foundPropertyNames = result.getColumnNames();
         Object[] realPropertyNames = singleValPropNames.toArray();

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SQLJcrPathTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SQLJcrPathTest.java?view=diff&r1=161750&r2=161751
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SQLJcrPathTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SQLJcrPathTest.java
Mon Apr 18 03:44:02 2005
@@ -18,7 +18,6 @@
 
 import org.apache.jackrabbit.test.NotExecutableException;
 
-import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.query.Query;
@@ -59,15 +58,12 @@
     }
     
     /**
-     * Verify that the jcr:path is the first property from the found property
-     * names, when explicitely declared in the select clause as the 1st
-     * property
-     * @throws NotExecutableException if the repository does not support the
-     *  jcr:path property in the query result.
+     * Verify that the jcr:path is the last property from the found property
+     * names when the query statement does not use a contains function.
      */
     public void testJcrPath() throws RepositoryException, NotExecutableException {
         String nodeTypeName = session.getRootNode().getPrimaryNodeType().getName();
-        String queryStatement = "select " + jcrPath + " from " + nodeTypeName;
+        String queryStatement = "select * from " + nodeTypeName;
 
         // execute the search query
         Query query = session.getWorkspace().getQueryManager().createQuery(queryStatement,
Query.SQL);
@@ -75,8 +71,8 @@
 
         String[] propNames = result.getColumnNames();
         if (propNames.length > 0) {
-            // jcr:path should be the first column
-            assertEquals(jcrPath + " should be the first property", jcrPath, propNames[0]);
+            // jcr:path should be the last column
+            assertEquals(jcrPath + " should be the last property", jcrPath, propNames[propNames.length
- 1]);
         }
     }
 }

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SQLQueryLevel2Test.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SQLQueryLevel2Test.java?view=diff&r1=161750&r2=161751
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SQLQueryLevel2Test.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SQLQueryLevel2Test.java
Mon Apr 18 03:44:02 2005
@@ -135,8 +135,6 @@
      */
     private Statement getFullTextStatement() {
         StringBuffer tmp = new StringBuffer("SELECT ");
-        tmp.append(jcrPath).append(", ");
-        tmp.append(jcrScore).append(", ");
         tmp.append(propertyName1);
         tmp.append(" FROM ").append(testNodeType);
         tmp.append(" WHERE CONTAINS(*, ");

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/XPathJcrPathTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/XPathJcrPathTest.java?view=diff&r1=161750&r2=161751
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/XPathJcrPathTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/XPathJcrPathTest.java
Mon Apr 18 03:44:02 2005
@@ -20,7 +20,6 @@
 
 import javax.jcr.Session;
 import javax.jcr.RepositoryException;
-import javax.jcr.Repository;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryResult;
 
@@ -59,15 +58,12 @@
     }
 
     /**
-     * Verify that the jcr:path is the first property from the found property
-     * names, when explicitely declared in query statement.
-     *
-     * @throws NotExecutableException if the repository does not support the
-     *                                jcr:path property in the query result.
+     * Verify that the jcr:path is the last property from the found property
+     * names when the query statement does not use a contains function.
      */
     public void testJcrPath() throws RepositoryException, NotExecutableException {
         String nodeTypeName = session.getRootNode().getPrimaryNodeType().getName();
-        String queryStatement = "//element(*, " + nodeTypeName + ")/@" + jcrPath;
+        String queryStatement = "//element(*, " + nodeTypeName + ")";
 
         // execute the search query
         Query query = session.getWorkspace().getQueryManager().createQuery(queryStatement,
Query.XPATH);
@@ -75,10 +71,8 @@
 
         String[] propNames = result.getColumnNames();
         if (propNames.length > 0) {
-            // jcr:path should be the first column
-            assertEquals(jcrPath + " should be the first property", jcrPath, propNames[0]);
+            // jcr:path should be the last column
+            assertEquals(jcrPath + " should be the last property", jcrPath, propNames[propNames.length
- 1]);
         }
     }
-
-
 }

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/XPathQueryLevel2Test.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/XPathQueryLevel2Test.java?view=diff&r1=161750&r2=161751
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/XPathQueryLevel2Test.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/XPathQueryLevel2Test.java
Mon Apr 18 03:44:02 2005
@@ -137,8 +137,7 @@
         tmp.append(jcrRoot).append(testRoot);
         tmp.append("/*[").append(jcrContains);
         tmp.append("(., \"'quick brown' -cat\")]");
-        tmp.append("/(@").append(jcrPath).append("|@").append(propertyName1);
-        tmp.append("|@").append(jcrScore).append(")");
+        tmp.append("/@").append(propertyName1);
         return new Statement(tmp.toString(), Query.XPATH);
     }
 



Mime
View raw message