mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
search link map will display only direct results
This commit is contained in:
parent
df9f6ce33a
commit
3cb368c4de
@ -11,6 +11,7 @@ const NoteRevision = require("./note_revision");
|
|||||||
const TaskContext = require("../../services/task_context");
|
const TaskContext = require("../../services/task_context");
|
||||||
const dayjs = require("dayjs");
|
const dayjs = require("dayjs");
|
||||||
const utc = require('dayjs/plugin/utc');
|
const utc = require('dayjs/plugin/utc');
|
||||||
|
const searchService = require("../../services/search/services/search.js");
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
|
|
||||||
const LABEL = 'label';
|
const LABEL = 'label';
|
||||||
@ -839,6 +840,27 @@ class Note extends AbstractEntity {
|
|||||||
return Array.from(set);
|
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}>}}
|
* @returns {{notes: Note[], relationships: Array.<{parentNoteId: string, childNoteId: string}>}}
|
||||||
*/
|
*/
|
||||||
@ -848,16 +870,8 @@ class Note extends AbstractEntity {
|
|||||||
|
|
||||||
function resolveSearchNote(searchNote) {
|
function resolveSearchNote(searchNote) {
|
||||||
try {
|
try {
|
||||||
const searchService = require("../../services/search/services/search");
|
for (const resultNote of searchNote.getSearchResultNotes()) {
|
||||||
const becca = searchNote.becca;
|
addSubtreeNotesInner(resultNote, searchNote);
|
||||||
const {searchResultNoteIds} = searchService.searchFromNote(searchNote);
|
|
||||||
|
|
||||||
for (const resultNoteId of searchResultNoteIds) {
|
|
||||||
const resultNote = becca.notes[resultNoteId];
|
|
||||||
|
|
||||||
if (resultNote) {
|
|
||||||
addSubtreeNotesInner(resultNote, searchNote);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
@ -37,7 +37,7 @@ function getNeighbors(note, depth) {
|
|||||||
const retNoteIds = [];
|
const retNoteIds = [];
|
||||||
|
|
||||||
function isIgnoredRelation(relation) {
|
function isIgnoredRelation(relation) {
|
||||||
return ['relationMapLink', 'template', 'image'].includes(relation.name);
|
return ['relationMapLink', 'template', 'image', 'ancestor'].includes(relation.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// forward links
|
// 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
|
// if the map root itself has exclude attribute (journal typically) then there wouldn't be anything to display, so
|
||||||
// we'll just ignore it
|
// we'll just ignore it
|
||||||
const ignoreExcludeFromNoteMap = mapRootNote.hasLabel('excludeFromNoteMap');
|
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(
|
const noteIds = new Set(
|
||||||
subtree.notes
|
unfilteredNotes
|
||||||
.filter(note => ignoreExcludeFromNoteMap || !note.hasLabel('excludeFromNoteMap'))
|
.filter(note => ignoreExcludeFromNoteMap || !note.hasLabel('excludeFromNoteMap'))
|
||||||
.map(note => note.noteId)
|
.map(note => note.noteId)
|
||||||
);
|
);
|
||||||
@ -102,6 +109,8 @@ function getLinkMap(req) {
|
|||||||
noteIds.add(noteId);
|
noteIds.add(noteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(noteIds);
|
||||||
|
|
||||||
const notes = Array.from(noteIds).map(noteId => {
|
const notes = Array.from(noteIds).map(noteId => {
|
||||||
const note = becca.getNote(noteId);
|
const note = becca.getNote(noteId);
|
||||||
|
|
||||||
@ -128,7 +137,7 @@ function getLinkMap(req) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.map(rel => ({
|
.map(rel => ({
|
||||||
id: rel.noteId + "-" + rel.name + "-" + rel.value,
|
id: rel.noteId + "-" + rel.name + "-" + rel.value,
|
||||||
sourceNoteId: rel.noteId,
|
sourceNoteId: rel.noteId,
|
||||||
targetNoteId: rel.value,
|
targetNoteId: rel.value,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user