diff --git a/www/index.html b/www/index.html
index 9b26e258..d291468e 100644
--- a/www/index.html
+++ b/www/index.html
@@ -652,6 +652,11 @@
(these are used to set appropriate alphabet for the Archive Index)
+
+ Set max number of search results to display:
+
+ (higher number will result in slower search performance)
+
diff --git a/www/js/app.js b/www/js/app.js
index 3bf48316..df0473be 100644
--- a/www/js/app.js
+++ b/www/js/app.js
@@ -29,11 +29,6 @@
define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cookies', 'q', 'transformStyles', 'kiwixServe'],
function ($, zimArchiveLoader, uiUtil, util, utf8, images, cookies, q, transformStyles, kiwixServe) {
- /**
- * Maximum number of articles to display in a search
- * @type Integer
- */
- var MAX_SEARCH_RESULT_SIZE = params.results; //This value is controlled in init.js, as are all parameters
/**
* The delay (in milliseconds) between two "keepalive" messages
* sent to the ServiceWorker (so that it is not stopped by
@@ -897,6 +892,12 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
this.value = params.omegaChar;
cookies.setItem('omegaChar', params.omegaChar, Infinity);
});
+ $('input:text[name=maxResults]').on('change', function (e) {
+ params.maxResults = this.value > 5 ? this.value : 5;
+ params.maxResults = params.maxResults < 50 ? params.maxResults : 50;
+ this.value = params.maxResults;
+ cookies.setItem('maxResults', params.maxResults, Infinity);
+ });
$('input:checkbox[name=hideToolbar]').on('change', function (e) {
params.hideToolbar = this.checked ? true : false;
cookies.setItem('hideToolbar', params.hideToolbar, Infinity);
@@ -2106,7 +2107,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
}
showZIMIndex(null, sel);
} else {
- state.selectedArchive.findDirEntriesWithPrefix(prefix.trim(), MAX_SEARCH_RESULT_SIZE, populateListOfArticles);
+ state.selectedArchive.findDirEntriesWithPrefix(prefix.trim(), params.maxResults, populateListOfArticles);
}
} else {
$('#searchingArticles').hide();
@@ -2119,7 +2120,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
}
/**
- * Extracts and displays in htmlArticle the first MAX_SEARCH_RESULT_SIZE articles beginning with start
+ * Extracts and displays in htmlArticle the first params.maxResults articles beginning with start
* @param {String} start Optional index number to begin the list with
* @param {String} prefix Optional search prefix from which to start an alphabetical search
*/
@@ -2131,7 +2132,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
prefix = start > 0 ? '' : prefix;
}
if (state.selectedArchive !== null && state.selectedArchive.isReady()) {
- state.selectedArchive.findDirEntriesWithPrefixCaseSensitive(prefix, MAX_SEARCH_RESULT_SIZE, function (dirEntryArray, nextStart) {
+ state.selectedArchive.findDirEntriesWithPrefixCaseSensitive(prefix, params.maxResults, function (dirEntryArray, nextStart) {
var docBody = document.getElementById('largeModal');
var newHtml = "";
for (var i = 0; i < dirEntryArray.length; i++) {
@@ -2140,10 +2141,10 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
"'>" + (dirEntry.getTitleOrUrl()) + "";
}
start = start ? start : 0;
- var back = start ? '<< Previous ' + MAX_SEARCH_RESULT_SIZE + ' ' : '';
- var next = dirEntryArray.length === MAX_SEARCH_RESULT_SIZE ? 'Next ' + MAX_SEARCH_RESULT_SIZE + ' >> ' : '';
+ var back = start ? '<< Previous ' + params.maxResults + ' ' : '';
+ var next = dirEntryArray.length === params.maxResults ? 'Next ' + params.maxResults + ' >> ' : '';
var backNext = back ? next ? back + ' | ' + next : back : next;
backNext = '' + backNext + '
\n';
var alphaSelector = [];
@@ -2240,8 +2241,8 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
var articleListHeaderMessageDiv = $('#articleListHeaderMessage');
var nbDirEntry = dirEntryArray ? dirEntryArray.length : 0;
var message;
- if (nbDirEntry >= MAX_SEARCH_RESULT_SIZE) {
- message = 'First ' + MAX_SEARCH_RESULT_SIZE + ' articles below (refine your search).';
+ if (nbDirEntry >= params.maxResults) {
+ message = 'First ' + params.maxResults + ' articles below (refine your search).';
} else {
message = nbDirEntry + ' articles found.';
}
@@ -2253,7 +2254,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
var articleListDiv = document.getElementById('articleList');
var articleListDivHtml = '';
- var listLength = dirEntryArray.length < MAX_SEARCH_RESULT_SIZE ? dirEntryArray.length : MAX_SEARCH_RESULT_SIZE;
+ var listLength = dirEntryArray.length < params.maxResults ? dirEntryArray.length : params.maxResults;
for (var i = 0; i < listLength; i++) {
var dirEntry = dirEntryArray[i];
var dirEntryStringId = uiUtil.htmlEscapeChars(dirEntry.toStringId());
diff --git a/www/js/init.js b/www/js/init.js
index 0bece9ee..d6c7fd84 100644
--- a/www/js/init.js
+++ b/www/js/init.js
@@ -39,7 +39,7 @@ params['cachedStartPage'] = false; //If you have cached the start page for quick
params['kiwixDownloadLink'] = "https://download.kiwix.org/zim/"; //Include final slash
params['cookieSupport'] = checkCookies();
-params['results'] = 20; //Number of search results to display
+params['maxResults'] = ~~(getCookie('maxResults') || 20); //Number of search results to display
params['relativeFontSize'] = ~~(getCookie('relativeFontSize') || 100); //Sets the initial font size for articles (as a percentage) - user can adjust using zoom buttons
params['relativeUIFontSize'] = ~~(getCookie('relativeUIFontSize') || 100); //Sets the initial font size for UI (as a percentage) - user can adjust using slider in Config
params['cssSource'] = getCookie('cssSource') || "auto"; //Set default to "auto", "desktop" or "mobile"
@@ -119,6 +119,7 @@ document.getElementById('hideActiveContentWarningCheck').checked = params.hideAc
document.getElementById('allowHTMLExtractionCheck').checked = params.allowHTMLExtraction;
document.getElementById('alphaCharTxt').value = params.alphaChar;
document.getElementById('omegaCharTxt').value = params.omegaChar;
+document.getElementById('maxResults').value = params.maxResults;
var versionSpans = document.getElementsByClassName('version');
for (var i = 0; i < versionSpans.length; i++) {