1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-10-06 22:17:10 +02:00

API: Add ability to search by folder or tag title

This commit is contained in:
Laurent Cozic
2020-01-20 02:19:57 +00:00
parent 6973bf9331
commit 3fed1abc36
6 changed files with 101 additions and 48 deletions

View File

@@ -247,7 +247,21 @@ class Api {
const query = request.query.query;
if (!query) throw new ErrorBadRequest('Missing "query" parameter');
return await SearchEngineUtils.notesForQuery(query, this.notePreviewsOptions_(request));
const queryType = request.query.type ? BaseModel.modelNameToType(request.query.type) : BaseModel.TYPE_NOTE;
if (queryType !== BaseItem.TYPE_NOTE) {
const ModelClass = BaseItem.getClassByItemType(queryType);
const options = {};
const fields = this.fields_(request, []);
if (fields.length) options.fields = fields;
const sqlQueryPart = query.replace(/\*/g, '%');
options.where = 'title LIKE ?';
options.whereParams = [sqlQueryPart];
options.caseInsensitive = true;
return await ModelClass.all(options);
} else {
return await SearchEngineUtils.notesForQuery(query, this.notePreviewsOptions_(request));
}
}
async action_folders(request, id = null, link = null) {