From ff5b84db10f0ac8a25344cc9426542c24817c713 Mon Sep 17 00:00:00 2001 From: azivner Date: Tue, 14 Aug 2018 22:50:05 +0200 Subject: [PATCH] search (note) fixes --- src/public/javascripts/services/tree.js | 1 + src/public/javascripts/services/tree_builder.js | 11 +++++++++-- src/routes/api/search.js | 3 ++- src/services/handlers.js | 8 +++++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.js index 831687cc3..6c75f6387 100644 --- a/src/public/javascripts/services/tree.js +++ b/src/public/javascripts/services/tree.js @@ -357,6 +357,7 @@ function initFancyTree(tree) { dnd: dragAndDropSetup, lazyLoad: function(event, data) { const noteId = data.node.data.noteId; + data.result = treeCache.getNote(noteId).then(note => treeBuilder.prepareBranch(note)); }, clones: { diff --git a/src/public/javascripts/services/tree_builder.js b/src/public/javascripts/services/tree_builder.js index 85a3336d3..4cb026a08 100644 --- a/src/public/javascripts/services/tree_builder.js +++ b/src/public/javascripts/services/tree_builder.js @@ -74,12 +74,17 @@ async function prepareRealBranch(parentNote) { async function prepareSearchBranch(note) { const fullNote = await noteDetailService.loadNote(note.noteId); - const results = await server.get('search/' + encodeURIComponent(fullNote.jsonContent.searchString)); + const results = (await server.get('search/' + encodeURIComponent(fullNote.jsonContent.searchString))) + .filter(res => res.noteId !== note.noteId); // this is necessary because title of the search note is often the same as the search text which would match and create circle const noteIds = results.map(res => res.noteId); + console.log("result: ", results); + // force to load all the notes at once instead of one by one - await treeCache.getNotes(noteIds); + const notes = await treeCache.getNotes(noteIds); + + console.log("NOTES", notes); for (const result of results) { const origBranch = await treeCache.getBranch(result.branchId); @@ -95,6 +100,8 @@ async function prepareSearchBranch(note) { treeCache.addBranch(branch); } + console.log("fullNote", fullNote); + return await prepareRealBranch(fullNote); } diff --git a/src/routes/api/search.js b/src/routes/api/search.js index bc190604b..a492b1f8f 100644 --- a/src/routes/api/search.js +++ b/src/routes/api/search.js @@ -38,7 +38,7 @@ async function searchNotes(req) { let results; if (labelFiltersNoteIds && searchTextResults) { - results = labelFiltersNoteIds.filter(item => searchTextResults.includes(item.noteId)); + results = searchTextResults.filter(item => labelFiltersNoteIds.includes(item.noteId)); } else if (labelFiltersNoteIds) { results = labelFiltersNoteIds.map(noteCacheService.getNotePath).filter(res => !!res); @@ -64,6 +64,7 @@ async function getFullTextResults(searchText) { FROM notes WHERE isDeleted = 0 AND isProtected = 0 + AND type IN ('text', 'code') AND ${tokenSql.join(' AND ')}`); return noteIds; diff --git a/src/services/handlers.js b/src/services/handlers.js index 0426a3554..3e70e2a2a 100644 --- a/src/services/handlers.js +++ b/src/services/handlers.js @@ -3,6 +3,7 @@ const scriptService = require('./script'); const treeService = require('./tree'); const messagingService = require('./messaging'); const repository = require('./repository'); +const log = require('./log'); async function runAttachedRelations(note, relationName, originEntity) { const attributes = await note.getAttributes(); @@ -11,7 +12,12 @@ async function runAttachedRelations(note, relationName, originEntity) { for (const relation of runRelations) { const scriptNote = await relation.getTargetNote(); - await scriptService.executeNote(scriptNote, originEntity); + if (scriptNote) { + await scriptService.executeNote(scriptNote, originEntity); + } + else { + log.error(`Target note ${relation.value} of atttribute ${relation.attributeId} has not been found.`); + } } }