1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-12-05 22:57:29 +02:00

Mobile: Fixes #382: Implemented new search engine for mobile and highlight searched words in notes

This commit is contained in:
Laurent Cozic
2018-12-16 18:32:42 +01:00
parent 3231bfaff0
commit b1898141c3
9 changed files with 112 additions and 56 deletions

View File

@@ -0,0 +1,32 @@
const SearchEngine = require('lib/services/SearchEngine');
const Note = require('lib/models/Note');
class SearchEngineUtils {
static async notesForQuery(query) {
const results = await SearchEngine.instance().search(query);
const noteIds = results.map(n => n.id);
const previewOptions = {
order: [],
fields: Note.previewFields(),
conditions: ['id IN ("' + noteIds.join('","') + '")'],
}
const notes = await Note.previews(null, previewOptions);
// By default, the notes will be returned in reverse order
// or maybe random order so sort them here in the correct order
// (search engine returns the results in order of relevance).
const sortedNotes = [];
for (let i = 0; i < notes.length; i++) {
const idx = noteIds.indexOf(notes[i].id);
sortedNotes[idx] = notes[i];
}
return sortedNotes;
}
}
module.exports = SearchEngineUtils;