diff --git a/src/public/app/services/link.js b/src/public/app/services/link.js
index 6a8711714..0b759ca91 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.js
index 7548712a4..c031a00aa 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.js
index 4e6357ad3..d18a664af 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 = `
diff --git a/src/routes/api/search.js b/src/routes/api/search.js
index d20aa0617..39f77139f 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.js
index 34165e005..45f60f2b0 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.js
index cb1a797f4..737a1c081 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.js
index 79d5afac1..9d3cbd371 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.js
index 8e08742ff..1550abe60 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);