<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Latest posts for the topic "Search Pagination is broken?"]]></title>
		<link>https://community.jforum.net/posts/list/3.page</link>
		<description><![CDATA[Latest messages posted in the topic "Search Pagination is broken?"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>Search Pagination is broken?</title>
				<description><![CDATA[ Steps followed:
<br>
1. Go to "Search" from the top menu
<br>
2. Type 'why' with default options selected
<br>
3. Click Search
<br>
<br>
<br>
[b]It says "Search Results: 34 records were found"
<br>
[/b]The first page renders 20 records
<br>
The second page renders 11 records, which were the last 11 records on the first page.
<br>
The third page renders 2 records, that were the last 2 records on page 2
<br>
<br>
<br>
<br>
[b]Similarly, search for 'suggestions'. It says - Search Results: 39 records were found
<br>
[/b]The first page renders 33 records
<br>
The second page renders 20 records, which were the last 20 records on the first page.
<br>
The third page renders 5 records, that were the last 5 records on page 2
<br>
<br>
<br>]]></description>
				<guid isPermaLink="true">https://community.jforum.net/posts/preList/251/1118.page</guid>
				<link>https://community.jforum.net/posts/preList/251/1118.page</link>
				<pubDate><![CDATA[Tue, 19 Jul 2022 20:16:21]]> GMT</pubDate>
				<author><![CDATA[ Komal Gupta]]></author>
			</item>
			<item>
				<title>Search Pagination is broken?</title>
				<description><![CDATA[ The base problem seems to be that the first page shows all 35 results, when it should only be showing 15.
<br>
<br>
So yes, that looks like a bug. I'll put it on my list.]]></description>
				<guid isPermaLink="true">https://community.jforum.net/posts/preList/251/1119.page</guid>
				<link>https://community.jforum.net/posts/preList/251/1119.page</link>
				<pubDate><![CDATA[Tue, 19 Jul 2022 23:41:19]]> GMT</pubDate>
				<author><![CDATA[ udittmer]]></author>
			</item>
			<item>
				<title>Re:Search Pagination is broken?</title>
				<description><![CDATA[ Sure.
<br>
<br>
Attaching the patch that worked for me in the next post. Feel free to use it if it looks good to you! Thanks!]]></description>
				<guid isPermaLink="true">https://community.jforum.net/posts/preList/251/1120.page</guid>
				<link>https://community.jforum.net/posts/preList/251/1120.page</link>
				<pubDate><![CDATA[Wed, 20 Jul 2022 14:59:31]]> GMT</pubDate>
				<author><![CDATA[ Komal Gupta]]></author>
			</item>
			<item>
				<title>Re:Search Pagination is broken?</title>
				<description><![CDATA[ [code]
<br>
<br>
Index: src/main/java/net/jforum/search/LuceneContentCollector.java
<br>
IDEA additional info:
<br>
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<br>
&lt;+&gt;UTF-8
<br>
===================================================================
<br>
--- src/main/java/net/jforum/search/LuceneContentCollector.java (revision 972)
<br>
+++ src/main/java/net/jforum/search/LuceneContentCollector.java (date 1658247453000)
<br>
@@ -66,6 +66,10 @@
<br>
<br>
import org.apache.log4j.Logger;
<br>
<br>
+import net.jforum.util.preferences.ConfigKeys;
<br>
+import net.jforum.util.preferences.SystemGlobals;
<br>
+
<br>
+
<br>
/**
<br>
* @author Rafael Steil
<br>
*/
<br>
@@ -75,19 +79,20 @@
<br>
<br>
private LuceneSettings settings;
<br>
<br>
- public LuceneContentCollector (LuceneSettings settings)
<br>
- {
<br>
+ public LuceneContentCollector(LuceneSettings settings) {
<br>
this.settings = settings;
<br>
}
<br>
<br>
public List&lt;Post&gt; collect (SearchArgs args, ScoreDoc[] results, Query query) {
<br>
try {
<br>
- int[] postIds = new int[results.length];
<br>
+ int recordsPerPage = SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE);
<br>
+ int finalResultSize = Math.min(recordsPerPage, results.length);
<br>
+ int[] postIds = new int[finalResultSize];
<br>
//LOGGER.debug("collect: results="+results.length+", args.fetchCount="+args.fetchCount());
<br>
<br>
IndexSearcher searcher = new IndexSearcher(DirectoryReader.open(this.settings.directory()));
<br>
for (int docIndex = args.startFrom(), i = 0;
<br>
- docIndex &lt; results.length;
<br>
+ i &lt; finalResultSize;
<br>
docIndex++, i++) {
<br>
ScoreDoc hit = results[docIndex];
<br>
Document doc = searcher.doc(hit.doc);
<br>
<br>
[/code]]]></description>
				<guid isPermaLink="true">https://community.jforum.net/posts/preList/251/1121.page</guid>
				<link>https://community.jforum.net/posts/preList/251/1121.page</link>
				<pubDate><![CDATA[Wed, 20 Jul 2022 15:00:43]]> GMT</pubDate>
				<author><![CDATA[ Komal Gupta]]></author>
			</item>
			<item>
				<title>Search Pagination is broken?</title>
				<description><![CDATA[ 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).]]></description>
				<guid isPermaLink="true">https://community.jforum.net/posts/preList/251/1122.page</guid>
				<link>https://community.jforum.net/posts/preList/251/1122.page</link>
				<pubDate><![CDATA[Wed, 20 Jul 2022 15:56:04]]> GMT</pubDate>
				<author><![CDATA[ udittmer]]></author>
			</item>
			<item>
				<title>Re:Search Pagination is broken?</title>
				<description><![CDATA[ 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.]]></description>
				<guid isPermaLink="true">https://community.jforum.net/posts/preList/251/1124.page</guid>
				<link>https://community.jforum.net/posts/preList/251/1124.page</link>
				<pubDate><![CDATA[Thu, 21 Jul 2022 01:29:50]]> GMT</pubDate>
				<author><![CDATA[ Komal Gupta]]></author>
			</item>
			<item>
				<title>Re:Search Pagination is broken?</title>
				<description><![CDATA[ [code]
<br>
Index: src/main/java/net/jforum/search/LuceneContentCollector.java
<br>
IDEA additional info:
<br>
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<br>
&lt;+&gt;UTF-8
<br>
===================================================================
<br>
--- src/main/java/net/jforum/search/LuceneContentCollector.java (revision 974)
<br>
+++ src/main/java/net/jforum/search/LuceneContentCollector.java (date 1658338387000)
<br>
@@ -64,33 +64,38 @@
<br>
import org.apache.lucene.search.highlight.QueryScorer;
<br>
import org.apache.lucene.search.highlight.SimpleHTMLFormatter;
<br>
<br>
+import net.jforum.util.preferences.ConfigKeys;
<br>
+import net.jforum.util.preferences.SystemGlobals;
<br>
+
<br>
import org.apache.log4j.Logger;
<br>
<br>
/**
<br>
* @author Rafael Steil
<br>
*/
<br>
-public class LuceneContentCollector
<br>
-{
<br>
+public class LuceneContentCollector {
<br>
private static final Logger LOGGER = Logger.getLogger(LuceneContentCollector.class);
<br>
<br>
private LuceneSettings settings;
<br>
<br>
- public LuceneContentCollector (LuceneSettings settings)
<br>
- {
<br>
+ public LuceneContentCollector(LuceneSettings settings) {
<br>
this.settings = settings;
<br>
}
<br>
<br>
- public List&lt;Post&gt; collect (SearchArgs args, ScoreDoc[] results, Query query) {
<br>
+ public List&lt;Post&gt; collect(SearchArgs args, ScoreDoc[] results, Query query, int totalHits) {
<br>
try {
<br>
- int finalResultSize = Math.min(args.fetchCount(), results.length - args.startFrom());
<br>
+ int finalResultSize = Math.min(args.fetchCount(), totalHits - args.startFrom());
<br>
+// LOGGER.debug(String.format("collect: results=%d, args.fetchCount=%d, args.startFrom=%d, finalResultSize=%d", results.length, args.fetchCount(), args.startFrom(), finalResultSize));
<br>
int[] postIds = new int[finalResultSize];
<br>
- //LOGGER.debug(String.format("collect: results=%d, args.fetchCount=%d, args.startFrom=%d",
<br>
- // results.length, args.fetchCount(), args.startFrom()));
<br>
<br>
IndexSearcher searcher = new IndexSearcher(DirectoryReader.open(this.settings.directory()));
<br>
- for (int docIndex = args.startFrom(), i = 0;
<br>
- i &lt; finalResultSize;
<br>
- docIndex++, i++) {
<br>
+
<br>
+ int docIndex = args.startFrom();
<br>
+ while (docIndex &gt; SystemGlobals.getIntValue(ConfigKeys.SEARCH_RESULT_LIMIT)) {
<br>
+ docIndex -= SystemGlobals.getIntValue(ConfigKeys.SEARCH_RESULT_LIMIT);
<br>
+ }
<br>
+ LOGGER.debug(String.format("docIndex=%d", docIndex));
<br>
+
<br>
+ for (int i = 0; i &lt; finalResultSize; docIndex++, i++) {
<br>
ScoreDoc hit = results[docIndex];
<br>
Document doc = searcher.doc(hit.doc);
<br>
postIds[i] = Integer.parseInt(doc.get(SearchFields.Keyword.POST_ID));
<br>
Index: src/main/java/net/jforum/search/LuceneSearch.java
<br>
IDEA additional info:
<br>
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<br>
&lt;+&gt;UTF-8
<br>
===================================================================
<br>
--- src/main/java/net/jforum/search/LuceneSearch.java (revision 974)
<br>
+++ src/main/java/net/jforum/search/LuceneSearch.java (date 1658338329000)
<br>
@@ -158,7 +158,7 @@
<br>
ScoreDoc[] docs = tfd.scoreDocs;
<br>
TotalHits th = tfd.totalHits;
<br>
if (th.value &gt; 0) {
<br>
- result = new SearchResult&lt;&gt;(resultCollector.collect(args, docs, query), (int) th.value);
<br>
+ result = new SearchResult&lt;&gt;(resultCollector.collect(args, docs, query, (int) th.value), (int) th.value);
<br>
} else {
<br>
result = new SearchResult&lt;&gt;(new ArrayList&lt;&gt;(), 0);
<br>
}
<br>
<br>
[/code]]]></description>
				<guid isPermaLink="true">https://community.jforum.net/posts/preList/251/1125.page</guid>
				<link>https://community.jforum.net/posts/preList/251/1125.page</link>
				<pubDate><![CDATA[Thu, 21 Jul 2022 01:35:16]]> GMT</pubDate>
				<author><![CDATA[ Komal Gupta]]></author>
			</item>
	</channel>
</rss>