2019-03-17 05:19:01 +08:00
|
|
|
const repository = require('./repository');
|
|
|
|
const sql = require('./sql');
|
2019-03-17 18:38:27 +08:00
|
|
|
const log = require('./log');
|
2019-03-17 05:19:01 +08:00
|
|
|
const parseFilters = require('./parse_filters');
|
|
|
|
const buildSearchQuery = require('./build_search_query');
|
|
|
|
|
|
|
|
async function searchForNotes(searchString) {
|
|
|
|
const filters = parseFilters(searchString);
|
|
|
|
|
|
|
|
const {query, params} = buildSearchQuery(filters);
|
|
|
|
|
2019-03-17 18:38:27 +08:00
|
|
|
try {
|
|
|
|
return await repository.getEntities(query, params);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
log.error("Search failed for " + query);
|
|
|
|
|
|
|
|
throw e;
|
|
|
|
}
|
2019-03-17 05:19:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
async function searchForNoteIds(searchString) {
|
|
|
|
const filters = parseFilters(searchString);
|
|
|
|
|
|
|
|
const {query, params} = buildSearchQuery(filters, 'notes.noteId');
|
|
|
|
|
2019-03-17 18:38:27 +08:00
|
|
|
try {
|
|
|
|
return await sql.getColumn(query, params);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
log.error("Search failed for " + query);
|
|
|
|
|
|
|
|
throw e;
|
|
|
|
}
|
2019-03-17 05:19:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
searchForNotes,
|
|
|
|
searchForNoteIds
|
|
|
|
};
|