### Eclipse Workspace Patch 1.0
#P jackrabbit-core
Index: src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
===================================================================
--- src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java (revision 1370664)
+++ src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java (working copy)
@@ -98,6 +98,13 @@
private int invalid = 0;
/**
+ * 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. This value is set
+ * whenever hits are obtained.
+ */
+ private int totalSize = 0;
+
+ /**
* If true nodes are returned in document order.
*/
protected final boolean docOrder;
@@ -295,6 +302,15 @@
// update numResults
numResults = result.getSize();
+
+ // check the remaining results for valid entries
+ ScoreNode[] sn = result.nextScoreNodes();
+ while (sn != null) {
+ if (isAccessGranted(sn)) {
+ totalSize++;
+ }
+ sn = result.nextScoreNodes();
+ }
} catch (IOException e) {
log.error("Exception while executing query: ", e);
// todo throw?
@@ -332,6 +348,7 @@
}
// check access
if (isAccessGranted(sn)) {
+ totalSize++;
collector.add(sn);
} else {
invalid++;
@@ -365,9 +382,7 @@
/**
* 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. This method may return
+ * will get get if you don't set any limit or offset. This method may return
* -1 if the total size is unknown.
*
* @return the total number of hits.
@@ -376,7 +391,7 @@
if (numResults == -1) {
return -1;
} else {
- return numResults - invalid;
+ return totalSize;
}
}