limit number of results to 200, other tweaks

pull/255/head
azivner 2018-04-18 20:56:23 +07:00
parent 52b445f70b
commit 834bfa39c7
2 changed files with 32 additions and 13 deletions

@ -9,7 +9,7 @@ async function getAutocomplete(req) {
return results.map(res => { return results.map(res => {
return { return {
value: res.title + '(' + res.path + ')', value: res.title + ' (' + res.path + ')',
title: res.title title: res.title
} }
}); });

@ -42,30 +42,49 @@ function getResults(query) {
} }
} }
results.sort((a, b) => a.title < b.title ? -1 : 1);
return results; return results;
} }
function search(noteIds, tokens, path, results) { function search(noteIds, tokens, path, results) {
if (!noteIds) { if (!noteIds || noteIds.length === 0) {
return; return;
} }
for (const noteId of noteIds) { if (tokens.length === 0) {
if (noteId === 'root') { let curNoteId = noteIds[0];
if (tokens.length === 0) {
const reversedPath = path.slice();
reversedPath.reverse();
const noteTitle = getNoteTitle(reversedPath); while (curNoteId !== 'root') {
path.push(curNoteId);
console.log(noteTitle); const parents = childToParent[curNoteId];
results.push({ if (!parents || parents.length === 0) {
title: noteTitle, return;
path: reversedPath.join('/')
});
} }
curNoteId = parents[0];
}
path.reverse();
const noteTitle = getNoteTitle(path);
results.push({
title: noteTitle,
path: path.join('/')
});
return;
}
for (const noteId of noteIds) {
if (results.length >= 200) {
return;
}
if (noteId === 'root') {
continue; continue;
} }