[Logo] JForum - Powering Communities
  [Search] 搜尋   [Recent Topics] 最新主題   [Hottest Topics] 熱門主題   [Top Downloads] 熱門下載   [Groups] 回首頁 
[Register] 會員註冊 /  [Login] 登入 


JForum 2.8.3 is out with various fixes and improvements. Read all about it here

Search Pagination is broken? RSS feed
討論區首頁 » Developer Forum
發表人 內容
Komal Gupta


註冊時間: 2020/8/7
文章: 12
離線
Steps followed:
1. Go to "Search" from the top menu
2. Type 'why' with default options selected
3. Click Search


It says "Search Results: 34 records were found"
The first page renders 20 records
The second page renders 11 records, which were the last 11 records on the first page.
The third page renders 2 records, that were the last 2 records on page 2



Similarly, search for 'suggestions'. It says - Search Results: 39 records were found
The first page renders 33 records
The second page renders 20 records, which were the last 20 records on the first page.
The third page renders 5 records, that were the last 5 records on page 2


udittmer


註冊時間: 2013/2/21
文章: 424
離線
The base problem seems to be that the first page shows all 35 results, when it should only be showing 15.

So yes, that looks like a bug. I'll put it on my list.

Ping & Net - my free Android app for TCP/IP network diagnostics
[Email] [WWW]
Komal Gupta


註冊時間: 2020/8/7
文章: 12
離線
Sure.

Attaching the patch that worked for me in the next post. Feel free to use it if it looks good to you! Thanks!
Komal Gupta


註冊時間: 2020/8/7
文章: 12
離線


Index: src/main/java/net/jforum/search/LuceneContentCollector.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/net/jforum/search/LuceneContentCollector.java (revision 972)
+++ src/main/java/net/jforum/search/LuceneContentCollector.java (date 1658247453000)
@@ -66,6 +66,10 @@

import org.apache.log4j.Logger;

+import net.jforum.util.preferences.ConfigKeys;
+import net.jforum.util.preferences.SystemGlobals;
+
+
/**
* @author Rafael Steil
*/
@@ -75,19 +79,20 @@

private LuceneSettings settings;

- public LuceneContentCollector (LuceneSettings settings)
- {
+ public LuceneContentCollector(LuceneSettings settings) {
this.settings = settings;
}

public List<Post> collect (SearchArgs args, ScoreDoc[] results, Query query) {
try {
- int[] postIds = new int[results.length];
+ int recordsPerPage = SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE);
+ int finalResultSize = Math.min(recordsPerPage, results.length);
+ int[] postIds = new int[finalResultSize];
//LOGGER.debug("collect: results="+results.length+", args.fetchCount="+args.fetchCount());

IndexSearcher searcher = new IndexSearcher(DirectoryReader.open(this.settings.directory()));
for (int docIndex = args.startFrom(), i = 0;
- docIndex < results.length;
+ i < finalResultSize;
docIndex++, i++) {
ScoreDoc hit = results[docIndex];
Document doc = searcher.doc(hit.doc);

udittmer


註冊時間: 2013/2/21
文章: 424
離線
Thanks for the patch, I've just committed it (minus a bug that caused an exception if the number of results on the last page wasn't the same as the number of topics per page).

Ping & Net - my free Android app for TCP/IP network diagnostics
[Email] [WWW]
Komal Gupta


註冊時間: 2020/8/7
文章: 12
離線
Thanks for catching that. Added another fix for when search result limit size is less than the total hits. Please find patch in the next post.
Komal Gupta


註冊時間: 2020/8/7
文章: 12
離線

Index: src/main/java/net/jforum/search/LuceneContentCollector.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/net/jforum/search/LuceneContentCollector.java (revision 974)
+++ src/main/java/net/jforum/search/LuceneContentCollector.java (date 1658338387000)
@@ -64,33 +64,38 @@
import org.apache.lucene.search.highlight.QueryScorer;
import org.apache.lucene.search.highlight.SimpleHTMLFormatter;

+import net.jforum.util.preferences.ConfigKeys;
+import net.jforum.util.preferences.SystemGlobals;
+
import org.apache.log4j.Logger;

/**
* @author Rafael Steil
*/
-public class LuceneContentCollector
-{
+public class LuceneContentCollector {
private static final Logger LOGGER = Logger.getLogger(LuceneContentCollector.class);

private LuceneSettings settings;

- public LuceneContentCollector (LuceneSettings settings)
- {
+ public LuceneContentCollector(LuceneSettings settings) {
this.settings = settings;
}

- public List<Post> collect (SearchArgs args, ScoreDoc[] results, Query query) {
+ public List<Post> collect(SearchArgs args, ScoreDoc[] results, Query query, int totalHits) {
try {
- int finalResultSize = Math.min(args.fetchCount(), results.length - args.startFrom());
+ int finalResultSize = Math.min(args.fetchCount(), totalHits - args.startFrom());
+// LOGGER.debug(String.format("collect: results=%d, args.fetchCount=%d, args.startFrom=%d, finalResultSize=%d", results.length, args.fetchCount(), args.startFrom(), finalResultSize));
int[] postIds = new int[finalResultSize];
- //LOGGER.debug(String.format("collect: results=%d, args.fetchCount=%d, args.startFrom=%d",
- // results.length, args.fetchCount(), args.startFrom()));

IndexSearcher searcher = new IndexSearcher(DirectoryReader.open(this.settings.directory()));
- for (int docIndex = args.startFrom(), i = 0;
- i < finalResultSize;
- docIndex++, i++) {
+
+ int docIndex = args.startFrom();
+ while (docIndex > SystemGlobals.getIntValue(ConfigKeys.SEARCH_RESULT_LIMIT)) {
+ docIndex -= SystemGlobals.getIntValue(ConfigKeys.SEARCH_RESULT_LIMIT);
+ }
+ LOGGER.debug(String.format("docIndex=%d", docIndex));
+
+ for (int i = 0; i < finalResultSize; docIndex++, i++) {
ScoreDoc hit = results[docIndex];
Document doc = searcher.doc(hit.doc);
postIds[i] = Integer.parseInt(doc.get(SearchFields.Keyword.POST_ID));
Index: src/main/java/net/jforum/search/LuceneSearch.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/net/jforum/search/LuceneSearch.java (revision 974)
+++ src/main/java/net/jforum/search/LuceneSearch.java (date 1658338329000)
@@ -158,7 +158,7 @@
ScoreDoc[] docs = tfd.scoreDocs;
TotalHits th = tfd.totalHits;
if (th.value > 0) {
- result = new SearchResult<>(resultCollector.collect(args, docs, query), (int) th.value);
+ result = new SearchResult<>(resultCollector.collect(args, docs, query, (int) th.value), (int) th.value);
} else {
result = new SearchResult<>(new ArrayList<>(), 0);
}

 
討論區首頁 » Developer Forum
前往:   
行動版
Powered by JForum 2.8.3 © 2023 JForum Team • Maintained by Andowson Chang and Ulf Dittmer