From b7df55eaa9e4a26f59f0bd9a0df81c2c2659390b Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 29 Nov 2015 14:42:32 +0100 Subject: [PATCH 1/2] Bugfix: ZIM sorts empty titles to the end. This should fix some cases where articles could not be found (basically anything in the lower half). --- www/js/lib/zimArchive.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/www/js/lib/zimArchive.js b/www/js/lib/zimArchive.js index 397198a9..886eb998 100644 --- a/www/js/lib/zimArchive.js +++ b/www/js/lib/zimArchive.js @@ -110,6 +110,8 @@ define(['zimfile', 'zimDirEntry', 'util'], var that = this; util.binarySearch(0, this._file.articleCount, function(i) { return that._file.dirEntryByTitleIndex(i).then(function(dirEntry) { + if (dirEntry.title == "") + return -1; // ZIM sorts empty titles (assets) to the end return prefix < dirEntry.title ? -1 : 1; }); }, true).then(function(firstIndex) { From a2da62415fda6bd2321f1014da42d8fb9b398513 Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 29 Nov 2015 14:44:59 +0100 Subject: [PATCH 2/2] Check the prefix during title search. Do not return article titles that do not start with the given prefix. --- www/js/lib/zimArchive.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/js/lib/zimArchive.js b/www/js/lib/zimArchive.js index 886eb998..ed95acea 100644 --- a/www/js/lib/zimArchive.js +++ b/www/js/lib/zimArchive.js @@ -115,13 +115,13 @@ define(['zimfile', 'zimDirEntry', 'util'], return prefix < dirEntry.title ? -1 : 1; }); }, true).then(function(firstIndex) { - //@todo do not add titles that do not have the right prefix var titles = []; var addTitles = function(index) { if (index >= firstIndex + resultSize || index >= that._file.articleCount) return titles; return that._file.dirEntryByTitleIndex(index).then(function(dirEntry) { - titles.push(that._dirEntryToTitleObject(dirEntry)); + if (dirEntry.title.slice(0, prefix.length) == prefix) + titles.push(that._dirEntryToTitleObject(dirEntry)); return addTitles(index + 1); }); };