Skip to content

Build your personal knowledge base with Trilium Notes

added random ordering

zadam02988ed2b376
diff --git a/src/public/app/widgets/search_options/order_by.js b/src/public/app/widgets/search_options/order_by.js
index 9d24a6e425..8e2085fd45 100644
--- a/src/public/app/widgets/search_options/order_by.js
+++ b/src/public/app/widgets/search_options/order_by.js
@@ -21,6 +21,7 @@ const TPL = `
<option value="ownedLabelCount">Number of labels</option>
<option value="ownedRelationCount">Number of relations</option>
<option value="targetRelationCount">Number of relations targeting the note</option>
+ <option value="random">Random order</option>
</select>
<select name="orderDirection" class="form-control w-auto d-inline">
diff --git a/src/services/search/value_extractor.js b/src/services/search/value_extractor.js
index 350be2ece8..6ff099ae28 100644
--- a/src/services/search/value_extractor.js
+++ b/src/services/search/value_extractor.js
@@ -69,7 +69,7 @@ class ValueExtractor {
i++;
}
- else if (pathEl in PROP_MAPPING) {
+ else if (pathEl in PROP_MAPPING || pathEl === 'random') {
if (i !== this.propertyPath.length - 1) {
return `${pathEl} is a terminal property specifier and must be at the end`;
}
@@ -113,6 +113,9 @@ class ValueExtractor {
else if (cur() === 'children') {
cursor = cursor.children[0];
}
+ else if (cur() === 'random') {
+ return Math.random();
+ }
else if (cur() in PROP_MAPPING) {
return cursor[PROP_MAPPING[cur()]];
}