mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-09 04:06: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)
|
||||
return lowerBound ? begin : null;
|
||||
var mid = Math.floor((begin + end) / 2);
|
||||
return query(mid).then(function (decision) {
|
||||
if (decision < 0)
|
||||
return query(mid).then(function(decision)
|
||||
{
|
||||
if (decision == -1)
|
||||
return binarySearch(begin, mid, query, lowerBound);
|
||||
else if (decision > 0)
|
||||
else if (decision == 1)
|
||||
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
|
||||
return mid;
|
||||
});
|
||||
|
@ -180,13 +180,22 @@ define(['zimfile', 'zimDirEntry', 'util', 'utf8'],
|
||||
*/
|
||||
ZIMArchive.prototype.findDirEntriesWithPrefixCaseSensitive = function(prefix, resultSize, callback) {
|
||||
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) {
|
||||
return that._file.dirEntryByTitleIndex(i).then(function(dirEntry) {
|
||||
if (dirEntry.namespace < "A")
|
||||
return 1;
|
||||
else if (dirEntry.namespace > "A")
|
||||
return -1;
|
||||
return prefix <= dirEntry.title ? -1 : 1;
|
||||
if (dirEntry.namespace < "A") vector = 1;
|
||||
if (dirEntry.namespace > "A") vector = -1;
|
||||
if (dirEntry.namespace !== "A") return vector;
|
||||
// We should now be in namespace A
|
||||
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) {
|
||||
var dirEntries = [];
|
||||
|
Loading…
x
Reference in New Issue
Block a user