jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r685139 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
Date Tue, 12 Aug 2008 13:04:58 GMT
Author: mreutegg
Date: Tue Aug 12 06:04:57 2008
New Revision: 685139

URL: http://svn.apache.org/viewvc?rev=685139&view=rev
Log:
JCR-1714: QueryImpl result offSet must be considered after security class grant the item

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java?rev=685139&r1=685138&r2=685139&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
Tue Aug 12 06:04:57 2008
@@ -293,19 +293,16 @@
             log.debug("query executed in {} ms",
                     new Long(System.currentTimeMillis() - time));
 
-            int start = resultNodes.size() + invalid + (int) offset;
-            time = System.currentTimeMillis();
-            result.skip(start);
-            for (ScoreNode[] sn = result.nextScoreNodes();
-                 sn != null && resultNodes.size() < maxResultSize;
-                 sn = result.nextScoreNodes()) {
-                // check access
-                if (isAccessGranted(sn)) {
-                    resultNodes.add(sn);
-                } else {
-                    invalid++;
-                }
+            if (resultNodes.isEmpty() && offset > 0) {
+                // collect result offset into dummy list
+                collectScoreNodes(result, new ArrayList(), offset);
+            } else {
+                int start = resultNodes.size() + invalid + (int) offset;
+                result.skip(start);
             }
+
+            time = System.currentTimeMillis();
+            collectScoreNodes(result, resultNodes, maxResultSize);
             log.debug("retrieved ScoreNodes in {} ms",
                     new Long(System.currentTimeMillis() - time));
 
@@ -326,6 +323,36 @@
     }
 
     /**
+     * Collect score nodes from <code>hits</code> into the <code>collector</code>
+     * list until the size of <code>collector</code> reaches <code>maxResults</code>
+     * or there are not more results.
+     *
+     * @param hits the raw hits.
+     * @param collector where the access checked score nodes are collected.
+     * @param maxResults the maximum number of results in the collector.
+     * @throws IOException if an error occurs while reading from hits.
+     * @throws RepositoryException if an error occurs while checking access rights.
+     */
+    private void collectScoreNodes(MultiColumnQueryHits hits,
+                                   List collector,
+                                   long maxResults)
+            throws IOException, RepositoryException {
+        while (collector.size() < maxResults) {
+            ScoreNode[] sn = hits.nextScoreNodes();
+            if (sn == null) {
+                // no more results
+                break;
+            }
+            // check access
+            if (isAccessGranted(sn)) {
+                collector.add(sn);
+            } else {
+                invalid++;
+            }
+        }
+    }
+
+    /**
      * Checks if access is granted to all <code>nodes</code>.
      *
      * @param nodes the nodes to check.



Mime
View raw message