trilium/src/routes/api/search.js

30 lines
783 B
JavaScript
Raw Normal View History

"use strict";
const noteService = require('../../services/notes');
2018-06-06 07:12:52 +08:00
const noteCacheService = require('../../services/note_cache');
const searchService = require('../../services/search');
async function searchNotes(req) {
const noteIds = await searchService.searchForNoteIds(req.params.searchString);
return noteIds.map(noteCacheService.getNotePath).filter(res => !!res);
}
async function saveSearchToNote(req) {
const noteContent = {
searchString: req.params.searchString
};
2018-06-06 07:12:52 +08:00
const {note} = await noteService.createNote('root', req.params.searchString, noteContent, {
json: true,
2018-03-26 11:25:17 +08:00
type: 'search',
mime: "application/json"
});
return { noteId: note.noteId };
}
module.exports = {
searchNotes,
saveSearchToNote
};