mirror of
https://github.com/zadam/trilium.git
synced 2025-02-27 00:29:21 +08:00
implemented @limit for search
This commit is contained in:
parent
15eaf67189
commit
f273b4334e
8 changed files with 251 additions and 40 deletions
|
@ -394,7 +394,7 @@ the backend.
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line296">line 296</a>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line310">line 310</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
@ -758,7 +758,7 @@ the backend.
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line184">line 184</a>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line198">line 198</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
@ -1044,7 +1044,7 @@ the backend.
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line197">line 197</a>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line211">line 211</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
@ -1224,7 +1224,7 @@ the backend.
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line145">line 145</a>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line159">line 159</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
@ -1423,7 +1423,7 @@ the backend.
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line135">line 135</a>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line149">line 149</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
@ -1523,7 +1523,7 @@ the backend.
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line301">line 301</a>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line315">line 315</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
@ -1981,7 +1981,7 @@ the backend.
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line225">line 225</a>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line239">line 239</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
@ -2739,7 +2739,7 @@ if some action needs to happen on only one specific instance.
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line244">line 244</a>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line258">line 258</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
@ -3084,7 +3084,7 @@ if some action needs to happen on only one specific instance.
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line114">line 114</a>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line128">line 128</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
@ -3280,7 +3280,7 @@ if some action needs to happen on only one specific instance.
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line124">line 124</a>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line138">line 138</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
@ -3384,7 +3384,7 @@ if some action needs to happen on only one specific instance.
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line216">line 216</a>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line230">line 230</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
@ -3560,7 +3560,7 @@ if some action needs to happen on only one specific instance.
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line235">line 235</a>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line249">line 249</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
@ -3713,7 +3713,7 @@ if some action needs to happen on only one specific instance.
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line253">line 253</a>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line267">line 267</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
@ -3861,7 +3861,7 @@ if some action needs to happen on only one specific instance.
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line208">line 208</a>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line222">line 222</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
@ -3891,6 +3891,160 @@ if some action needs to happen on only one specific instance.
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="searchForNote"><span class="type-signature"></span>searchForNote<span class="signature">(searchString)</span><span class="type-signature"> → {Promise.<(<a href="Note.html">Note</a>|null)>}</span></h4>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="description">
|
||||
This is a powerful search method - you can search by attributes and their values, e.g.:
|
||||
"@dateModified =* MONTH AND @log". See full documentation for all options at: https://github.com/zadam/trilium/wiki/Search
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h5>Parameters:</h5>
|
||||
|
||||
|
||||
<table class="params">
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
<th>Name</th>
|
||||
|
||||
|
||||
<th>Type</th>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<th class="last">Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="name"><code>searchString</code></td>
|
||||
|
||||
|
||||
<td class="type">
|
||||
|
||||
|
||||
<span class="param-type">string</span>
|
||||
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<td class="description last"></td>
|
||||
</tr>
|
||||
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line114">line 114</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h5>Returns:</h5>
|
||||
|
||||
|
||||
|
||||
|
||||
<dl>
|
||||
<dt>
|
||||
Type
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
<span class="param-type">Promise.<(<a href="Note.html">Note</a>|null)></span>
|
||||
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -4023,10 +4177,6 @@ if some action needs to happen on only one specific instance.
|
|||
<h5>Returns:</h5>
|
||||
|
||||
|
||||
<div class="param-desc">
|
||||
$
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<dl>
|
||||
|
@ -4231,7 +4381,7 @@ This method looks similar to toggleNoteInParent() but differs because we're look
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line273">line 273</a>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line287">line 287</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
@ -4362,7 +4512,7 @@ This method looks similar to toggleNoteInParent() but differs because we're look
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line260">line 260</a>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line274">line 274</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
@ -4576,7 +4726,7 @@ This method looks similar to toggleNoteInParent() but differs because we're look
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line157">line 157</a>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line171">line 171</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
@ -4733,7 +4883,7 @@ transactional by default.
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line286">line 286</a>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line300">line 300</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
|
|
@ -272,7 +272,7 @@
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line159">line 159</a>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line173">line 173</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
@ -558,7 +558,7 @@
|
|||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line166">line 166</a>
|
||||
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line180">line 180</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
|
|
@ -127,10 +127,24 @@ function BackendScriptApi(currentNote, apiParams) {
|
|||
*
|
||||
* @method
|
||||
* @param {string} searchString
|
||||
* @returns ${Promise<Note[]>}
|
||||
* @returns {Promise<Note[]>}
|
||||
*/
|
||||
this.searchForNotes = searchService.searchForNotes;
|
||||
|
||||
/**
|
||||
* This is a powerful search method - you can search by attributes and their values, e.g.:
|
||||
* "@dateModified =* MONTH AND @log". See full documentation for all options at: https://github.com/zadam/trilium/wiki/Search
|
||||
*
|
||||
* @method
|
||||
* @param {string} searchString
|
||||
* @returns {Promise<Note|null>}
|
||||
*/
|
||||
this.searchForNote = async searchString => {
|
||||
const notes = await searchService.searchForNotes(searchString);
|
||||
|
||||
return notes.length > 0 ? notes[0] : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves notes with given label name & value
|
||||
*
|
||||
|
|
|
@ -99,10 +99,24 @@ function BackendScriptApi(currentNote, apiParams) {
|
|||
*
|
||||
* @method
|
||||
* @param {string} searchString
|
||||
* @returns ${Promise<Note[]>}
|
||||
* @returns {Promise<Note[]>}
|
||||
*/
|
||||
this.searchForNotes = searchService.searchForNotes;
|
||||
|
||||
/**
|
||||
* This is a powerful search method - you can search by attributes and their values, e.g.:
|
||||
* "@dateModified =* MONTH AND @log". See full documentation for all options at: https://github.com/zadam/trilium/wiki/Search
|
||||
*
|
||||
* @method
|
||||
* @param {string} searchString
|
||||
* @returns {Promise<Note|null>}
|
||||
*/
|
||||
this.searchForNote = async searchString => {
|
||||
const notes = await searchService.searchForNotes(searchString);
|
||||
|
||||
return notes.length > 0 ? notes[0] : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves notes with given label name & value
|
||||
*
|
||||
|
|
|
@ -67,8 +67,8 @@ module.exports = function(filters, selectedColumns = 'notes.*') {
|
|||
const params = [];
|
||||
|
||||
for (const filter of filters) {
|
||||
if (filter.name.toLowerCase() === 'orderby') {
|
||||
continue; // orderby is not real filter
|
||||
if (['orderby', 'limit'].includes(filter.name.toLowerCase())) {
|
||||
continue; // orderby and limit are not real filters
|
||||
}
|
||||
|
||||
where += " " + filter.relation + " ";
|
||||
|
|
|
@ -376,6 +376,16 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED
|
|||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @param noteId
|
||||
* @returns {boolean} - true if note exists (is not deleted) and is not archived.
|
||||
*/
|
||||
function isAvailable(noteId) {
|
||||
const notePath = getNotePath(noteId);
|
||||
|
||||
return !!notePath;
|
||||
}
|
||||
|
||||
eventService.subscribe(eventService.ENTER_PROTECTED_SESSION, () => {
|
||||
if (loaded) {
|
||||
loadProtectedNotes();
|
||||
|
@ -388,5 +398,6 @@ module.exports = {
|
|||
findNotes,
|
||||
getNotePath,
|
||||
getNoteTitleForPath,
|
||||
isAvailable,
|
||||
load
|
||||
};
|
|
@ -42,6 +42,21 @@ async function getNote(noteId) {
|
|||
return await getEntity("SELECT * FROM notes WHERE noteId = ?", [noteId]);
|
||||
}
|
||||
|
||||
/** @returns {Promise<Note[]>} */
|
||||
async function getNotes(noteIds) {
|
||||
// this note might be optimised, but remember that it must keep the existing order of noteIds
|
||||
// (important e.g. for @orderBy in search)
|
||||
const notes = [];
|
||||
|
||||
for (const noteId of noteIds) {
|
||||
const note = await getNote(noteId);
|
||||
|
||||
notes.push(note);
|
||||
}
|
||||
|
||||
return notes;
|
||||
}
|
||||
|
||||
/** @returns {Promise<Branch|null>} */
|
||||
async function getBranch(branchId) {
|
||||
return await getEntity("SELECT * FROM branches WHERE branchId = ?", [branchId]);
|
||||
|
@ -125,6 +140,7 @@ module.exports = {
|
|||
getEntities,
|
||||
getEntity,
|
||||
getNote,
|
||||
getNotes,
|
||||
getBranch,
|
||||
getAttribute,
|
||||
getOption,
|
||||
|
|
|
@ -3,20 +3,12 @@ const sql = require('./sql');
|
|||
const log = require('./log');
|
||||
const parseFilters = require('./parse_filters');
|
||||
const buildSearchQuery = require('./build_search_query');
|
||||
const noteCacheService = require('./note_cache');
|
||||
|
||||
async function searchForNotes(searchString) {
|
||||
const filters = parseFilters(searchString);
|
||||
const noteIds = await searchForNoteIds(searchString);
|
||||
|
||||
const {query, params} = buildSearchQuery(filters);
|
||||
|
||||
try {
|
||||
return await repository.getEntities(query, params);
|
||||
}
|
||||
catch (e) {
|
||||
log.error("Search failed for " + query);
|
||||
|
||||
throw e;
|
||||
}
|
||||
return await repository.getNotes(noteIds);
|
||||
}
|
||||
|
||||
async function searchForNoteIds(searchString) {
|
||||
|
@ -25,7 +17,21 @@ async function searchForNoteIds(searchString) {
|
|||
const {query, params} = buildSearchQuery(filters, 'notes.noteId');
|
||||
|
||||
try {
|
||||
return await sql.getColumn(query, params);
|
||||
const noteIds = await sql.getColumn(query, params);
|
||||
|
||||
const availableNoteIds = noteIds.filter(noteCacheService.isAvailable);
|
||||
|
||||
const limitFilter = filters.find(filter => filter.name.toLowerCase() === 'limit');
|
||||
|
||||
if (limitFilter) {
|
||||
const limit = parseInt(limitFilter.value);
|
||||
|
||||
return availableNoteIds.splice(0, limit);
|
||||
}
|
||||
else {
|
||||
return availableNoteIds;
|
||||
}
|
||||
|
||||
}
|
||||
catch (e) {
|
||||
log.error("Search failed for " + query);
|
||||
|
|
Loading…
Reference in a new issue