mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
added "limit" search modifier to search definition
This commit is contained in:
parent
a78c8ddad7
commit
f528799fed
49
src/public/app/widgets/search_options/limit.js
Normal file
49
src/public/app/widgets/search_options/limit.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import AbstractSearchOption from "./abstract_search_option.js";
|
||||||
|
|
||||||
|
const TPL = `
|
||||||
|
<tr data-search-option-conf="limit">
|
||||||
|
<td class="title-column">
|
||||||
|
<span class="bx bx-stop"></span>
|
||||||
|
|
||||||
|
Limit
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input name="limit" class="form-control" type="number" min="1" step="1" />
|
||||||
|
</td>
|
||||||
|
<td class="button-column">
|
||||||
|
<div class="dropdown help-dropdown">
|
||||||
|
<span class="bx bx-help-circle icon-action" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></span>
|
||||||
|
<div class="dropdown-menu dropdown-menu-right p-4">
|
||||||
|
Take only first X specified results.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span class="bx bx-x icon-action search-option-del"></span>
|
||||||
|
</td>
|
||||||
|
</tr>`;
|
||||||
|
|
||||||
|
export default class Limit extends AbstractSearchOption {
|
||||||
|
static get optionName() { return "limit" };
|
||||||
|
static get attributeType() { return "label" };
|
||||||
|
|
||||||
|
static async create(noteId) {
|
||||||
|
await AbstractSearchOption.setAttribute(noteId, 'label', 'limit', '10');
|
||||||
|
}
|
||||||
|
|
||||||
|
doRender() {
|
||||||
|
const $option = $(TPL);
|
||||||
|
|
||||||
|
this.$limit = $option.find('input[name=limit]');
|
||||||
|
this.$limit.on('change', () => this.update());
|
||||||
|
this.$limit.on('input', () => this.update());
|
||||||
|
this.$limit.val(this.note.getLabelValue('limit'));
|
||||||
|
|
||||||
|
return $option;
|
||||||
|
}
|
||||||
|
|
||||||
|
async update() {
|
||||||
|
const limit = this.$limit.val();
|
||||||
|
|
||||||
|
await this.setAttribute('label', 'limit', limit);
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,7 @@ import Ancestor from "../search_options/ancestor.js";
|
|||||||
import IncludeArchivedNotes from "../search_options/include_archived_notes.js";
|
import IncludeArchivedNotes from "../search_options/include_archived_notes.js";
|
||||||
import OrderBy from "../search_options/order_by.js";
|
import OrderBy from "../search_options/order_by.js";
|
||||||
import SearchScript from "../search_options/search_script.js";
|
import SearchScript from "../search_options/search_script.js";
|
||||||
|
import Limit from "../search_options/limit.js";
|
||||||
|
|
||||||
const TPL = `
|
const TPL = `
|
||||||
<div class="search-definition-widget">
|
<div class="search-definition-widget">
|
||||||
@ -106,6 +107,11 @@ const TPL = `
|
|||||||
order by
|
order by
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<button type="button" class="btn btn-sm" data-search-option-add="limit" title="Limit number of results">
|
||||||
|
<span class="bx bx-stop"></span>
|
||||||
|
limit
|
||||||
|
</button>
|
||||||
|
|
||||||
<div class="dropdown" style="display: inline-block;">
|
<div class="dropdown" style="display: inline-block;">
|
||||||
<button class="btn btn-sm dropdown-toggle action-add-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
<button class="btn btn-sm dropdown-toggle action-add-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
<span class="bx bxs-zap"></span>
|
<span class="bx bxs-zap"></span>
|
||||||
@ -163,7 +169,8 @@ const OPTION_CLASSES = [
|
|||||||
Ancestor,
|
Ancestor,
|
||||||
FastSearch,
|
FastSearch,
|
||||||
IncludeArchivedNotes,
|
IncludeArchivedNotes,
|
||||||
OrderBy
|
OrderBy,
|
||||||
|
Limit
|
||||||
];
|
];
|
||||||
|
|
||||||
const ACTION_CLASSES = {};
|
const ACTION_CLASSES = {};
|
||||||
|
@ -22,6 +22,7 @@ async function search(note) {
|
|||||||
includeArchivedNotes: note.hasLabel('includeArchivedNotes'),
|
includeArchivedNotes: note.hasLabel('includeArchivedNotes'),
|
||||||
orderBy: note.getLabelValue('orderBy'),
|
orderBy: note.getLabelValue('orderBy'),
|
||||||
orderDirection: note.getLabelValue('orderDirection'),
|
orderDirection: note.getLabelValue('orderDirection'),
|
||||||
|
limit: note.getLabelValue('limit'),
|
||||||
fuzzyAttributeSearch: false
|
fuzzyAttributeSearch: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ class OrderByAndLimitExp extends Expression {
|
|||||||
od.larger = od.direction === "asc" ? 1 : -1;
|
od.larger = od.direction === "asc" ? 1 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.limit = limit;
|
this.limit = limit || 0;
|
||||||
|
|
||||||
/** @type {Expression} */
|
/** @type {Expression} */
|
||||||
this.subExpression = null; // it's expected to be set after construction
|
this.subExpression = null; // it's expected to be set after construction
|
||||||
|
@ -10,6 +10,7 @@ class SearchContext {
|
|||||||
this.includeArchivedNotes = !!params.includeArchivedNotes;
|
this.includeArchivedNotes = !!params.includeArchivedNotes;
|
||||||
this.orderBy = params.orderBy;
|
this.orderBy = params.orderBy;
|
||||||
this.orderDirection = params.orderDirection;
|
this.orderDirection = params.orderDirection;
|
||||||
|
this.limit = params.limit;
|
||||||
this.fuzzyAttributeSearch = !!params.fuzzyAttributeSearch;
|
this.fuzzyAttributeSearch = !!params.fuzzyAttributeSearch;
|
||||||
this.highlightedTokens = [];
|
this.highlightedTokens = [];
|
||||||
this.originalQuery = "";
|
this.originalQuery = "";
|
||||||
|
@ -421,7 +421,7 @@ function parse({fulltextTokens, expressionTokens, searchContext}) {
|
|||||||
exp = new OrderByAndLimitExp([{
|
exp = new OrderByAndLimitExp([{
|
||||||
valueExtractor: new ValueExtractor(searchContext, ['note', searchContext.orderBy]),
|
valueExtractor: new ValueExtractor(searchContext, ['note', searchContext.orderBy]),
|
||||||
direction: searchContext.orderDirection
|
direction: searchContext.orderDirection
|
||||||
}], 0);
|
}], searchContext.limit);
|
||||||
|
|
||||||
exp.subExpression = filterExp;
|
exp.subExpression = filterExp;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user