You've already forked joplin
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:
32
ReactNativeClient/lib/services/SearchEngineUtils.js
Normal file
32
ReactNativeClient/lib/services/SearchEngineUtils.js
Normal 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;
|
||||
Reference in New Issue
Block a user