Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
script api search ignores hoisting by default
zadamc43b20ec2bd3
diff --git a/src/public/app/services/link.js b/src/public/app/services/link.jsindex 6a8711714a..0b759ca91e 100644--- a/src/public/app/services/link.js+++ b/src/public/app/services/link.js@@ -74,12 +74,8 @@ function goToLink(e) {const $link = $(e.target).closest("a,.block-link");- console.log("zzzzz", $link);-const notePath = getNotePathFromLink($link);- console.log()-if (notePath) {if ((e.which === 1 && e.ctrlKey) || e.which === 2) {appContext.tabManager.openTabWithNoteWithHoisting(notePath);@@ -96,8 +92,6 @@ function goToLink(e) {) {const address = $link.attr('href');- console.log("address", address);-if (address) {if (address.toLowerCase().startsWith('http')) {window.open(address, '_blank');diff --git a/src/public/app/services/search.js b/src/public/app/services/search.jsindex 7548712a47..c031a00aa0 100644--- a/src/public/app/services/search.js+++ b/src/public/app/services/search.js@@ -6,7 +6,7 @@ async function searchForNoteIds(searchString) {}async function searchForNotes(searchString) {- const noteIds = await server.get('search/' + encodeURIComponent(searchString));+ const noteIds = await searchForNoteIds(searchString);return await treeCache.getNotes(noteIds);}diff --git a/src/public/app/widgets/note_paths.js b/src/public/app/widgets/note_paths.jsindex 4e6357ad37..d18a664af5 100644--- a/src/public/app/widgets/note_paths.js+++ b/src/public/app/widgets/note_paths.js@@ -1,7 +1,6 @@import TabAwareWidget from "./tab_aware_widget.js";import treeService from "../services/tree.js";import linkService from "../services/link.js";-import hoistedNoteService from "../services/hoisted_note.js";const TPL = `<div class="dropdown note-paths-widget">diff --git a/src/routes/api/search.js b/src/routes/api/search.jsindex d20aa0617e..39f77139f2 100644--- a/src/routes/api/search.js+++ b/src/routes/api/search.js@@ -225,7 +225,8 @@ function search(req) {const searchContext = new SearchContext({fastSearch: false,includeArchivedNotes: true,- fuzzyAttributeSearch: false+ fuzzyAttributeSearch: false,+ ignoreHoistedNote: true});return searchService.findNotesWithQuery(searchString, searchContext)diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.jsindex 34165e0056..45f60f2b01 100644--- a/src/services/backend_script_api.js+++ b/src/services/backend_script_api.js@@ -102,6 +102,10 @@ function BackendScriptApi(currentNote, apiParams) {searchParams.includeArchivedNotes = true;}+ if (searchParams.ignoreHoistedNote === undefined) {+ searchParams.ignoreHoistedNote = true;+ }+const noteIds = searchService.findNotesWithQuery(query, new SearchContext(searchParams)).map(sr => sr.noteId);diff --git a/src/services/note_cache/note_cache_service.js b/src/services/note_cache/note_cache_service.jsindex cb1a797f4c..737a1c0812 100644--- a/src/services/note_cache/note_cache_service.js+++ b/src/services/note_cache/note_cache_service.js@@ -125,12 +125,18 @@ function getNoteTitleForPath(notePathArray) {* - this means that archived paths is returned only if there's no non-archived path* - you can check whether returned path is archived using isArchived()*/-function getSomePath(note, path = []) {+function getSomePath(note) {+ // first try to find note within hoisted note, otherwise take any existing note path+ return getSomePathInner(note, [], true)+ || getSomePathInner(note, [], false);+}++function getSomePathInner(note, path, respectHoistng) {if (note.noteId === 'root') {path.push(note.noteId);path.reverse();- if (!path.includes(cls.getHoistedNoteId())) {+ if (respectHoistng && !path.includes(cls.getHoistedNoteId())) {return false;}@@ -143,7 +149,7 @@ function getSomePath(note, path = []) {}for (const parentNote of parents) {- const retPath = getSomePath(parentNote, path.concat([note.noteId]));+ const retPath = getSomePathInner(parentNote, path.concat([note.noteId]), respectHoistng);if (retPath) {return retPath;diff --git a/src/services/search/search_context.js b/src/services/search/search_context.jsindex 79d5afac12..9d3cbd3719 100644--- a/src/services/search/search_context.js+++ b/src/services/search/search_context.js@@ -5,9 +5,15 @@ const cls = require('../cls');class SearchContext {constructor(params = {}) {this.fastSearch = !!params.fastSearch;- this.ancestorNoteId = params.ancestorNoteId || cls.getHoistedNoteId();- this.ancestorDepth = params.ancestorDepth;this.includeArchivedNotes = !!params.includeArchivedNotes;+ this.ignoreHoistedNote = !!params.ignoreHoistedNote;+ this.ancestorNoteId = params.ancestorNoteId;++ if (!this.ancestorNoteId && !this.ignoreHoistedNote) {+ this.ancestorNoteId = cls.getHoistedNoteId();+ }++ this.ancestorDepth = params.ancestorDepth;this.orderBy = params.orderBy;this.orderDirection = params.orderDirection;this.limit = params.limit;diff --git a/src/services/search/services/search.js b/src/services/search/services/search.jsindex 8e08742fff..1550abe605 100644--- a/src/services/search/services/search.js+++ b/src/services/search/services/search.js@@ -9,7 +9,6 @@ const SearchContext = require("../search_context.js");const noteCache = require('../../note_cache/note_cache.js');const noteCacheService = require('../../note_cache/note_cache_service.js');const utils = require('../../utils.js');-const cls = require('../../cls.js');const log = require('../../log.js');function loadNeededInfoFromDatabase() {@@ -65,10 +64,7 @@ function loadNeededInfoFromDatabase() {* @return {SearchResult[]}*/function findNotesWithExpression(expression, searchContext) {- const hoistedNote = noteCache.notes[cls.getHoistedNoteId()];- let allNotes = (hoistedNote && hoistedNote.noteId !== 'root')- ? hoistedNote.subtreeNotes- : Object.values(noteCache.notes);+ let allNotes = Object.values(noteCache.notes);if (searchContext.dbLoadNeeded) {loadNeededInfoFromDatabase();@@ -87,9 +83,9 @@ function findNotesWithExpression(expression, searchContext) {const noteSet = expression.execute(allNoteSet, executionContext);const searchResults = noteSet.notes- .map(note => executionContext.noteIdToNotePath[note.noteId] || noteCacheService.getSomePath(note))- .filter(notePathArray => notePathArray && notePathArray.includes(cls.getHoistedNoteId()))- .map(notePathArray => new SearchResult(notePathArray));+ .map(note => new SearchResult(+ executionContext.noteIdToNotePath[note.noteId] || noteCacheService.getSomePath(note)+ ));for (const res of searchResults) {res.computeScore(searchContext.highlightedTokens);