1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-02 12:47:41 +02:00

All: Fixes: Wrong field removed in API search (#5066)

This commit is contained in:
JackGruber 2021-06-11 01:24:50 +02:00 committed by GitHub
parent 24a586c537
commit 01e6ca4616
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 4 deletions

View File

@ -83,4 +83,25 @@ describe('services_SearchEngineUtils', function() {
expect(rows.map(r=>r.id)).toContain(todo2.id);
}));
});
it('remove auto added fields', (async () => {
await Note.save({ title: 'abcd', body: 'body 1' });
await searchEngine.syncTables();
const testCases = [
['title', 'todo_due'],
['title', 'todo_completed'],
['title'],
['title', 'todo_completed', 'todo_due'],
];
for (const testCase of testCases) {
const rows = await SearchEngineUtils.notesForQuery('abcd', false, { fields: [...testCase] }, searchEngine);
testCase.push('type_');
expect(Object.keys(rows[0]).length).toBe(testCase.length);
for (const field of testCase) {
expect(rows[0]).toHaveProperty(field);
}
}
}));
});

View File

@ -38,10 +38,10 @@ export default class SearchEngineUtils {
isTodoAutoAdded = true;
}
let isTodoCompletedAutoAdded = false;
let todoCompletedAutoAdded = false;
if (fields.indexOf('todo_completed') < 0) {
fields.push('todo_completed');
isTodoCompletedAutoAdded = true;
todoCompletedAutoAdded = true;
}
const previewOptions = Object.assign({}, {
@ -66,8 +66,8 @@ export default class SearchEngineUtils {
const idx = noteIds.indexOf(filteredNotes[i].id);
sortedNotes[idx] = filteredNotes[i];
if (idWasAutoAdded) delete sortedNotes[idx].id;
if (isTodoCompletedAutoAdded) delete sortedNotes[idx].is_todo;
if (isTodoAutoAdded) delete sortedNotes[idx].todo_completed;
if (todoCompletedAutoAdded) delete sortedNotes[idx].todo_completed;
if (isTodoAutoAdded) delete sortedNotes[idx].is_todo;
}
// Note that when the search engine index is somehow corrupted, it might contain