From 55356963dd70610650ef87d5867f0224a4704d60 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 1 Sep 2019 11:33:45 +0200 Subject: [PATCH] improvements to similar notes - now using dice's coefficient for better results --- package-lock.json | 5 + package.json | 1 + .../javascripts/widgets/similar_notes.js | 16 ++-- src/routes/api/similar_notes.js | 9 +- src/services/note_cache.js | 92 +++++++++++++++++-- 5 files changed, 104 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8098ac4a3..5eed89d9e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12215,6 +12215,11 @@ "resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz", "integrity": "sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM=" }, + "string-similarity": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/string-similarity/-/string-similarity-3.0.0.tgz", + "integrity": "sha512-7kS7LyTp56OqOI2BDWQNVnLX/rCxIQn+/5M0op1WV6P8Xx6TZNdajpuqQdiJ7Xx+p1C5CsWMvdiBp9ApMhxzEQ==" + }, "string-width": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", diff --git a/package.json b/package.json index 678d0e73d..052af115f 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "simple-node-logger": "18.12.23", "sqlite": "3.0.3", "sqlite3": "4.1.0", + "string-similarity": "^3.0.0", "tar-stream": "2.1.0", "turndown": "5.0.3", "unescape": "1.0.1", diff --git a/src/public/javascripts/widgets/similar_notes.js b/src/public/javascripts/widgets/similar_notes.js index 2492f9f4a..dae891045 100644 --- a/src/public/javascripts/widgets/similar_notes.js +++ b/src/public/javascripts/widgets/similar_notes.js @@ -2,6 +2,7 @@ import StandardWidget from "./standard_widget.js"; import linkService from "../services/link.js"; import server from "../services/server.js"; import treeCache from "../services/tree_cache.js"; +import treeUtils from "../services/tree_utils.js"; class SimilarNotesWidget extends StandardWidget { getWidgetTitle() { return "Similar notes"; } @@ -9,20 +10,23 @@ class SimilarNotesWidget extends StandardWidget { getMaxHeight() { return "200px"; } async doRenderBody() { - const similarNoteIds = await server.get('similar_notes/' + this.ctx.note.noteId); + const similarNotes = await server.get('similar_notes/' + this.ctx.note.noteId); - if (similarNoteIds.length === 0) { + if (similarNotes.length === 0) { this.$body.text("No similar notes found ..."); return; } - await treeCache.getNotes(similarNoteIds); // preload all at once + await treeCache.getNotes(similarNotes.map(note => note.noteId)); // preload all at once - const $list = $("