trilium/src/routes/api/search.js

37 lines
1 KiB
JavaScript
Raw Normal View History

"use strict";
const sql = require('../../services/sql');
2019-02-16 04:21:26 +08:00
const utils = require('../../services/utils');
const noteService = require('../../services/notes');
2018-06-06 07:12:52 +08:00
const noteCacheService = require('../../services/note_cache');
const parseFilters = require('../../services/parse_filters');
const buildSearchQuery = require('../../services/build_search_query');
async function searchNotes(req) {
2019-03-16 23:52:58 +08:00
const filters = parseFilters(req.params.searchString);
2019-03-16 23:52:58 +08:00
const {query, params} = buildSearchQuery(filters);
2019-03-16 23:52:58 +08:00
const labelFiltersNoteIds = await sql.getColumn(query, params);
2019-03-16 23:52:58 +08:00
return labelFiltersNoteIds.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
};