mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
script api search ignores hoisting by default
This commit is contained in:
parent
2d0cb5b66e
commit
c43b20ec2b
@ -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');
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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">
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user