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);
}