Skip to content

Build your personal knowledge base with Trilium Notes

similarity tweaks

zadam6220b02ef083
diff --git a/src/public/app/widgets/similar_notes.js b/src/public/app/widgets/similar_notes.js
index 0dc32e351e..019c21aa1e 100644
--- a/src/public/app/widgets/similar_notes.js
+++ b/src/public/app/widgets/similar_notes.js
@@ -8,7 +8,7 @@ const TPL = `
<div class="similar-notes-widget hide-in-zen-mode">
<style>
.similar-notes-wrapper {
- max-height: 100px;
+ max-height: 75px;
overflow: auto;
}
diff --git a/src/services/note_cache/entities/note.js b/src/services/note_cache/entities/note.js
index 7c39dd4ffd..d5bdfc35b6 100644
--- a/src/services/note_cache/entities/note.js
+++ b/src/services/note_cache/entities/note.js
@@ -332,6 +332,18 @@ class Note {
this.isDecrypted = true;
}
}
+
+ // for logging etc
+ get pojo() {
+ const pojo = {...this};
+
+ delete pojo.noteCache;
+ delete pojo.ancestorCache;
+ delete pojo.attributeCache;
+ delete pojo.flatTextCache;
+
+ return pojo;
+ }
}
module.exports = Note;
diff --git a/src/services/note_cache/similarity.js b/src/services/note_cache/similarity.js
index d762368aa3..831e9acbcb 100644
--- a/src/services/note_cache/similarity.js
+++ b/src/services/note_cache/similarity.js
@@ -6,7 +6,21 @@ const IGNORED_ATTR_NAMES = [
"includenotelink",
"internallink",
"imagelink",
- "relationmaplink"
+ "relationmaplink",
+ "template",
+ "disableversioning",
+ "archived",
+ "hidepromotedattributes",
+ "keyboardshortcut",
+ "bookzoomlevel",
+ "noteinfowidgetdisabled",
+ "linkmapwidgetdisabled",
+ "noterevisionswidgetdisabled",
+ "whatlinksherewidgetdisabled",
+ "similarnoteswidgetdisabled",
+ "disableinclusion",
+ "rendernote",
+ "pageurl",
];
function filterLabelValue(value) {
@@ -41,6 +55,10 @@ function buildRewardMap(note) {
}
for (const ancestorNote of note.ancestors) {
+ if (ancestorNote.noteId === 'root') {
+ continue;
+ }
+
if (ancestorNote.isDecrypted) {
addToRewardMap(ancestorNote.title, 0.3);
}
@@ -61,6 +79,12 @@ function buildRewardMap(note) {
}
for (const attr of note.attributes) {
+ if (attr.name.startsWith('child:')
+ || attr.name.startsWith('relation:')
+ || attr.name.startsWith('label:')) {
+ continue;
+ }
+
// inherited notes get small penalization
const reward = note.noteId === attr.noteId ? 0.8 : 0.5;
@@ -213,6 +237,12 @@ async function findSimilarNotes(noteId) {
}
for (const attr of candidateNote.attributes) {
+ if (attr.name.startsWith('child:')
+ || attr.name.startsWith('relation:')
+ || attr.name.startsWith('label:')) {
+ continue;
+ }
+
if (!IGNORED_ATTR_NAMES.includes(attr.name)) {
score += gatherRewards(attr.name);
}
@@ -277,6 +307,16 @@ async function findSimilarNotes(noteId) {
results.sort((a, b) => a.score > b.score ? -1 : 1);
+ results.forEach(r => {
+ const note = noteCache.notes[r.noteId];
+
+ if (!note.isDecrypted) {
+ console.log(note.pojo);
+ }
+ });
+
+ console.log(rewardMap);
+
return results.length > 200 ? results.slice(0, 200) : results;
}