mirror of
https://github.com/zadam/trilium.git
synced 2025-11-11 07:45:51 +01:00
basic implementation of "similar notes" widget
This commit is contained in:
24
src/routes/api/similar_notes.js
Normal file
24
src/routes/api/similar_notes.js
Normal file
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
|
||||
const noteCacheService = require('../../services/note_cache');
|
||||
const repository = require('../../services/repository');
|
||||
|
||||
async function getSimilarNotes(req) {
|
||||
const noteId = req.params.noteId;
|
||||
|
||||
const note = await repository.getNote(noteId);
|
||||
|
||||
if (!note) {
|
||||
return [404, `Note ${noteId} not found.`];
|
||||
}
|
||||
|
||||
const results = await noteCacheService.findNotes(note.title);
|
||||
|
||||
return results
|
||||
.map(r => r.noteId)
|
||||
.filter(similarNoteId => similarNoteId !== noteId);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getSimilarNotes
|
||||
};
|
||||
Reference in New Issue
Block a user