mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
similar notes algorithm tweaks (WIP)
This commit is contained in:
parent
bff5b015ea
commit
056c40c0d0
@ -101,9 +101,9 @@ export default class SimilarNotesWidget extends TabAwareWidget {
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
async refreshWithNote(note) {
|
||||
async refresh() {
|
||||
// remember which title was when we found the similar notes
|
||||
this.title = note.title;
|
||||
this.title = this.note.title;
|
||||
|
||||
const similarNotes = await server.get('similar-notes/' + this.noteId);
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
const noteCacheService = require('../../services/note_cache/note_cache_service');
|
||||
const repository = require('../../services/repository');
|
||||
|
||||
function getSimilarNotes(req) {
|
||||
async function getSimilarNotes(req) {
|
||||
const noteId = req.params.noteId;
|
||||
|
||||
const note = repository.getNote(noteId);
|
||||
@ -12,7 +12,7 @@ function getSimilarNotes(req) {
|
||||
return [404, `Note ${noteId} not found.`];
|
||||
}
|
||||
|
||||
const results = noteCacheService.findSimilarNotes(noteId);
|
||||
const results = await noteCacheService.findSimilarNotes(noteId);
|
||||
|
||||
return results
|
||||
.filter(note => note.noteId !== noteId);
|
||||
|
@ -157,7 +157,7 @@ class Note {
|
||||
*/
|
||||
get flatText() {
|
||||
if (!this.flatTextCache) {
|
||||
this.flatTextCache = this.noteId + ' ' + this.type + ' ' + this.mime + ' ' + this.dateCreated.substr(0, 16) + ' ';
|
||||
this.flatTextCache = this.noteId + ' ' + this.type + ' ' + this.mime + ' ';
|
||||
|
||||
for (const branch of this.parentBranches) {
|
||||
if (branch.prefix) {
|
||||
|
@ -5,6 +5,7 @@ const hoistedNoteService = require('../hoisted_note');
|
||||
const protectedSessionService = require('../protected_session');
|
||||
const stringSimilarity = require('string-similarity');
|
||||
const log = require('../log');
|
||||
const dateUtils = require('../date_utils');
|
||||
|
||||
function isNotePathArchived(notePath) {
|
||||
const noteId = notePath[notePath.length - 1];
|
||||
@ -174,8 +175,22 @@ function getNotePath(noteId) {
|
||||
}
|
||||
}
|
||||
|
||||
function evaluateSimilarity(sourceNote, candidateNote, results) {
|
||||
function evaluateSimilarity(sourceNote, candidateNote, dates, results) {
|
||||
let coeff = stringSimilarity.compareTwoStrings(sourceNote.flatText, candidateNote.flatText);
|
||||
const {utcDateCreated} = candidateNote;
|
||||
|
||||
/**
|
||||
* We want to improve standing of notes which have been created in similar time to each other since
|
||||
* there's a good chance they are related.
|
||||
*
|
||||
* But there's an exception - if they were created really close to each other (withing few seconds) then
|
||||
* they are probably part of the import and not created by hand - these OTOH should not benefit.
|
||||
*/
|
||||
if (utcDateCreated >= dates.minDate && utcDateCreated <= dates.maxDate
|
||||
&& utcDateCreated < dates.minExcludedDate && utcDateCreated > dates.maxExcludedDate) {
|
||||
|
||||
coeff += 0.3;
|
||||
}
|
||||
|
||||
if (coeff > 0.5) {
|
||||
const notePath = getSomePath(candidateNote);
|
||||
@ -203,7 +218,7 @@ function setImmediatePromise() {
|
||||
});
|
||||
}
|
||||
|
||||
function findSimilarNotes(noteId) {
|
||||
async function findSimilarNotes(noteId) {
|
||||
const results = [];
|
||||
let i = 0;
|
||||
|
||||
@ -213,17 +228,28 @@ function findSimilarNotes(noteId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const dateCreatedTs = dateUtils.parseDateTime(origNote.utcDateCreated);
|
||||
|
||||
const dates = {
|
||||
minDate: dateUtils.utcDateStr(new Date(dateCreatedTs - 1800)),
|
||||
minExcludedDate: dateUtils.utcDateStr(new Date(dateCreatedTs - 5)),
|
||||
maxExcludedDate: dateUtils.utcDateStr(new Date(dateCreatedTs + 5)),
|
||||
maxDate: dateUtils.utcDateStr(new Date(dateCreatedTs + 1800)),
|
||||
};
|
||||
|
||||
console.log("ORIG:", origNote.flatText);
|
||||
|
||||
for (const note of Object.values(noteCache.notes)) {
|
||||
if (note.noteId === origNote.noteId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
evaluateSimilarity(origNote, note, results);
|
||||
evaluateSimilarity(origNote, note, dates, results);
|
||||
|
||||
i++;
|
||||
|
||||
if (i % 200 === 0) {
|
||||
setImmediatePromise();
|
||||
await setImmediatePromise();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user