jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cki...@apache.org
Subject svn commit: r572889 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/LazyQueryResultImpl.java test/java/org/apache/jackrabbit/core/query/LimitAndOffsetTest.java
Date Wed, 05 Sep 2007 06:55:55 GMT
Author: ckiehl
Date: Tue Sep  4 23:55:54 2007
New Revision: 572889

URL: http://svn.apache.org/viewvc?rev=572889&view=rev
Log:
JCR-1073: Added getTotalSize() to LazyQueryResultImpl

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LazyQueryResultImpl.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/LimitAndOffsetTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LazyQueryResultImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LazyQueryResultImpl.java?rev=572889&r1=572888&r2=572889&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LazyQueryResultImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LazyQueryResultImpl.java
Tue Sep  4 23:55:54 2007
@@ -47,7 +47,7 @@
     /**
      * The logger instance for this class
      */
-    private static final Logger log = LoggerFactory.getLogger(QueryResultImpl.class);
+    private static final Logger log = LoggerFactory.getLogger(LazyQueryResultImpl.class);
 
     /**
      * The search index to execute the query.
@@ -285,18 +285,14 @@
                 numResults = result.length();
             }
 
-            int start = resultNodes.size() + invalid;
+            int start = resultNodes.size() + invalid + (int)offset;
             int max = Math.min(result.length(), numResults);
             for (int i = start; i < max && resultNodes.size() < maxResultSize;
i++) {
                 NodeId id = NodeId.valueOf(result.doc(i).get(FieldNames.UUID));
                 // check access
                 try {
                     if (accessMgr.isGranted(id, AccessManager.READ)) {
-                        if (i < offset) {
-                            invalid++;
-                        } else {
-                            resultNodes.add(new ScoreNode(id, result.score(i)));
-                        }
+                        resultNodes.add(new ScoreNode(id, result.score(i)));
                     } else {
                         invalid++;
                     }
@@ -318,6 +314,16 @@
             }
         }
     }
+    
+    /**
+     * Returns the total number of hits. This is the number of results you
+     * will get get if you don't set any limit or offset. Keep in mind that this
+     * number may get smaller if nodes are found in the result set which the
+     * current session has no permission to access.
+     */
+    public int getTotalSize() {
+        return numResults - invalid;
+    }
 
     private final class LazyScoreNodeIterator implements ScoreNodeIterator {
 
@@ -396,11 +402,11 @@
          * nodes or the session does not have access to a node.
          */
         public long getSize() {
-            int totalSize = numResults - invalid;
+            int totalSize = getTotalSize();
             if (limit > 0 && totalSize > limit) {
                 return limit;
             } else {
-                return totalSize;
+                return totalSize - offset;
             }
         }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/LimitAndOffsetTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/LimitAndOffsetTest.java?rev=572889&r1=572888&r2=572889&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/LimitAndOffsetTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/LimitAndOffsetTest.java
Tue Sep  4 23:55:54 2007
@@ -8,6 +8,8 @@
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.QueryResult;
 
+import org.apache.jackrabbit.core.query.lucene.LazyQueryResultImpl;
+
 public class LimitAndOffsetTest extends AbstractQueryTest {
 
     private Node node1;
@@ -100,12 +102,14 @@
         QueryResult result = query.execute();
         NodeIterator nodes = result.getNodes();
         assertEquals(2, nodes.getSize());
+        assertEquals(3, ((LazyQueryResultImpl) result).getTotalSize());
 
         query.setOffset(1);
         query.setLimit(1);
         result = query.execute();
         nodes = result.getNodes();
         assertEquals(1, nodes.getSize());
+        assertEquals(3, ((LazyQueryResultImpl) result).getTotalSize());
     }
 
 }



Mime
View raw message