in src/docHelper.js [267:319]
export function searchOutlineAsync(queryString, numberLimit = 50) {
return getOutlineAsync().then(() => {
let lists = [];
for (let i = 0; i < allNodesPaths.length; i++) {
if (lists.length >= numberLimit) {
return lists;
}
let p = allNodesPaths[i];
if (p.indexOf(queryString) >= 0) {
lists.push(getOutlineNode(p));
}
}
if (lists.length < numberLimit) {
if (!querySearchScores) {
querySearchScores = new Uint8Array(allNodesPaths.length);
}
let matchScoreCount = 0;
for (let i = 0; i < allNodesPaths.length; i++) {
querySearchScores[i] = stringSimilarity(allNodesPaths[i], queryString) * 255;
if (querySearchScores[i] > 50) {
matchScoreCount++;
}
}
let picked = {};
let safeCount = 0;
let safeProtect = 200;
while (lists.length < numberLimit && matchScoreCount > 0) {
let maxScore = 0;
let maxIndex;
for (let i = 0; i < querySearchScores.length; i++) {
if (querySearchScores[i] > maxScore && !picked[i]) {
maxIndex = i;
maxScore = querySearchScores[i];
}
}
if (maxScore > 50) { // Threshold
picked[maxIndex] = true;
lists.push(getOutlineNode(allNodesPaths[maxIndex]));
matchScoreCount--;
}
safeCount++;
if (safeCount > safeProtect) {
break;
}
}
}
return lists;
});
}