snoopdave commented on code in PR #226:
URL: https://github.com/apache/roller/pull/226#discussion_r4406656436


##########
app/src/main/java/org/apache/roller/weblogger/business/search/lucene/LuceneIndexManager.java:
##########
@@ -432,44 +432,50 @@ static SearchResultList convertHitsToEntryList(
 
         List<WeblogEntryWrapper> results = new ArrayList<>();
 
-        // determine offset
-        int offset = pageNum * entryCount;
-        if (offset >= hits.length) {
-            offset = 0;
-        }
-
-        // determine limit
-        int limit = entryCount;
-        if (offset + limit > hits.length) {
-            limit = hits.length - offset;
-        }
-
         try {
-            Set<String> categories = new TreeSet<>();
-            TreeSet<String> categorySet = new TreeSet<>();
             Weblogger roller = WebloggerFactory.getWeblogger();
             WeblogEntryManager weblogMgr = roller.getWeblogEntryManager();
 
-            WeblogEntry entry;
-            Document doc;
-            String handle;
+            // The index can lag behind the entries, so page through the hits
+            // whose entry is published now (and not a future post). Only
+            // those count toward the offset and limit.
+            List<WeblogEntry> visible = new ArrayList<>();
+            List<Document> visibleDocs = new ArrayList<>();
             Timestamp now = new Timestamp(new Date().getTime());
-            for (int i = offset; i < offset + limit; i++) {
-                doc = search.getSearcher().doc(hits[i].doc);
-                handle = 
doc.getField(FieldConstants.WEBSITE_HANDLE).stringValue();
-                entry = 
weblogMgr.getWeblogEntry(doc.getField(FieldConstants.ID).stringValue());
+            for (ScoreDoc hit : hits) {

Review Comment:
   🤖Claude: fixed by stopping the loop once it has `(pageNum + 1) * entryCount` 
visible entries. A page now loads about as many entries as it shows, plus any 
drafts it skips. If the hits run out first, the loop has seen them all, so a 
page past the end still falls back to the first page as before. New 
`SearchHitPagingTest` (mocks, no database) checks the load counts: 2 for a 
first page of 2, 3 when a draft comes first, and all 20 for a page past the 
end. The first two fail without the early stop. Full `app` suite on JDK 11: 420 
run, 0 failures, 1 skipped. (Local change, in the next push.)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to