mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-10 04:40:27 -04:00
Fix incomplete searches in some ZIM files
Former-commit-id: cb0cd14bd44a005d0a1fa784847ac7fe41bfca37 [formerly 17a97e25963e921a257b4de53b2e5c8df90e63ad] Former-commit-id: f4666707e53b4478de6f0efeb0d8eba1e0e18da1
This commit is contained in:
parent
6148e739f9
commit
f5b95f4e28
@ -236,11 +236,16 @@ define(['q'], function (q) {
|
|||||||
if (end <= begin)
|
if (end <= begin)
|
||||||
return lowerBound ? begin : null;
|
return lowerBound ? begin : null;
|
||||||
var mid = Math.floor((begin + end) / 2);
|
var mid = Math.floor((begin + end) / 2);
|
||||||
return query(mid).then(function (decision) {
|
return query(mid).then(function(decision)
|
||||||
if (decision < 0)
|
{
|
||||||
|
if (decision == -1)
|
||||||
return binarySearch(begin, mid, query, lowerBound);
|
return binarySearch(begin, mid, query, lowerBound);
|
||||||
else if (decision > 0)
|
else if (decision == 1)
|
||||||
return binarySearch(mid + 1, end, query, lowerBound);
|
return binarySearch(mid + 1, end, query, lowerBound);
|
||||||
|
else if (decision == -2)
|
||||||
|
return binarySearch(begin, end - 1, query, lowerBound)
|
||||||
|
else if (decision == 2)
|
||||||
|
return binarySearch(begin + 1, end, query, lowerBound)
|
||||||
else
|
else
|
||||||
return mid;
|
return mid;
|
||||||
});
|
});
|
||||||
|
@ -180,13 +180,22 @@ define(['zimfile', 'zimDirEntry', 'util', 'utf8'],
|
|||||||
*/
|
*/
|
||||||
ZIMArchive.prototype.findDirEntriesWithPrefixCaseSensitive = function(prefix, resultSize, callback) {
|
ZIMArchive.prototype.findDirEntriesWithPrefixCaseSensitive = function(prefix, resultSize, callback) {
|
||||||
var that = this;
|
var that = this;
|
||||||
|
// Vector is used to remember the search direction if we encounter a dirEntry with an empty title
|
||||||
|
var vector = -1;
|
||||||
util.binarySearch(0, this._file.articleCount, function(i) {
|
util.binarySearch(0, this._file.articleCount, function(i) {
|
||||||
return that._file.dirEntryByTitleIndex(i).then(function(dirEntry) {
|
return that._file.dirEntryByTitleIndex(i).then(function(dirEntry) {
|
||||||
if (dirEntry.namespace < "A")
|
if (dirEntry.namespace < "A") vector = 1;
|
||||||
return 1;
|
if (dirEntry.namespace > "A") vector = -1;
|
||||||
else if (dirEntry.namespace > "A")
|
if (dirEntry.namespace !== "A") return vector;
|
||||||
return -1;
|
// We should now be in namespace A
|
||||||
return prefix <= dirEntry.title ? -1 : 1;
|
if (dirEntry.title) {
|
||||||
|
vector = prefix <= dirEntry.title ? -1 : 1;
|
||||||
|
return vector;
|
||||||
|
} else {
|
||||||
|
// Since there is no title, we must nudge the search algorith up or down
|
||||||
|
// We signal this to util.binarySearch by returning -2 or +2 instead of -1 or +1
|
||||||
|
return vector + vector;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}, true).then(function(firstIndex) {
|
}, true).then(function(firstIndex) {
|
||||||
var dirEntries = [];
|
var dirEntries = [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user