search link map will display only direct results

This commit is contained in:
zadam 2022-11-07 23:56:53 +01:00
parent df9f6ce33a
commit 3cb368c4de
2 changed files with 37 additions and 14 deletions

View File

@ -11,6 +11,7 @@ const NoteRevision = require("./note_revision");
const TaskContext = require("../../services/task_context");
const dayjs = require("dayjs");
const utc = require('dayjs/plugin/utc');
const searchService = require("../../services/search/services/search.js");
dayjs.extend(utc)
const LABEL = 'label';
@ -839,6 +840,27 @@ class Note extends AbstractEntity {
return Array.from(set);
}
/** @return {Note[]} */
getSearchResultNotes() {
if (this.type !== 'search') {
return [];
}
try {
const searchService = require("../../services/search/services/search");
const {searchResultNoteIds} = searchService.searchFromNote(this);
const becca = this.becca;
return searchResultNoteIds
.map(resultNoteId => becca.notes[resultNoteId])
.filter(note => !!note);
}
catch (e) {
log.error(`Could not resolve search note ${this.noteId}: ${e.message}`);
return [];
}
}
/**
* @returns {{notes: Note[], relationships: Array.<{parentNoteId: string, childNoteId: string}>}}
*/
@ -848,16 +870,8 @@ class Note extends AbstractEntity {
function resolveSearchNote(searchNote) {
try {
const searchService = require("../../services/search/services/search");
const becca = searchNote.becca;
const {searchResultNoteIds} = searchService.searchFromNote(searchNote);
for (const resultNoteId of searchResultNoteIds) {
const resultNote = becca.notes[resultNoteId];
if (resultNote) {
addSubtreeNotesInner(resultNote, searchNote);
}
for (const resultNote of searchNote.getSearchResultNotes()) {
addSubtreeNotesInner(resultNote, searchNote);
}
}
catch (e) {

View File

@ -37,7 +37,7 @@ function getNeighbors(note, depth) {
const retNoteIds = [];
function isIgnoredRelation(relation) {
return ['relationMapLink', 'template', 'image'].includes(relation.name);
return ['relationMapLink', 'template', 'image', 'ancestor'].includes(relation.name);
}
// forward links
@ -86,10 +86,17 @@ function getLinkMap(req) {
// if the map root itself has exclude attribute (journal typically) then there wouldn't be anything to display, so
// we'll just ignore it
const ignoreExcludeFromNoteMap = mapRootNote.hasLabel('excludeFromNoteMap');
const subtree = mapRootNote.getSubtree({includeArchived: false, resolveSearch: true});
let unfilteredNotes;
if (mapRootNote.type === 'search') {
// for search notes we want to consider the direct search results only without the descendants
unfilteredNotes = mapRootNote.getSearchResultNotes();
} else {
unfilteredNotes = mapRootNote.getSubtree({includeArchived: false, resolveSearch: true}).notes;
}
const noteIds = new Set(
subtree.notes
unfilteredNotes
.filter(note => ignoreExcludeFromNoteMap || !note.hasLabel('excludeFromNoteMap'))
.map(note => note.noteId)
);
@ -102,6 +109,8 @@ function getLinkMap(req) {
noteIds.add(noteId);
}
console.log(noteIds);
const notes = Array.from(noteIds).map(noteId => {
const note = becca.getNote(noteId);
@ -128,7 +137,7 @@ function getLinkMap(req) {
return true;
}
})
.map(rel => ({
.map(rel => ({
id: rel.noteId + "-" + rel.name + "-" + rel.value,
sourceNoteId: rel.noteId,
targetNoteId: rel.value,