mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 13:39:01 +01:00 
			
		
		
		
	fixes to saved search
This commit is contained in:
		
							parent
							
								
									d037420acb
								
							
						
					
					
						commit
						0b38e24185
					
				
							
								
								
									
										6
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										6
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							@ -2762,9 +2762,9 @@
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "dayjs": {
 | 
					    "dayjs": {
 | 
				
			||||||
      "version": "1.8.33",
 | 
					      "version": "1.8.34",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.8.33.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.8.34.tgz",
 | 
				
			||||||
      "integrity": "sha512-881TDLZCdpJFKbraWRHcUG8zfMLLX400ENf9rFZDuWc5zYMss6xifo2PhlDX0ftOmR2NRmaIY47bAa4gKQfXqw=="
 | 
					      "integrity": "sha512-Olb+E6EoMvdPmAMq2QoucuyZycKHjTlBXmRx8Ada+wGtq4SIXuDCdtoaX4KkK0yjf1fJLnwXQURr8gQKWKaybw=="
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "debug": {
 | 
					    "debug": {
 | 
				
			||||||
      "version": "4.1.1",
 | 
					      "version": "4.1.1",
 | 
				
			||||||
 | 
				
			|||||||
@ -32,7 +32,7 @@
 | 
				
			|||||||
    "commonmark": "0.29.1",
 | 
					    "commonmark": "0.29.1",
 | 
				
			||||||
    "cookie-parser": "1.4.5",
 | 
					    "cookie-parser": "1.4.5",
 | 
				
			||||||
    "csurf": "1.11.0",
 | 
					    "csurf": "1.11.0",
 | 
				
			||||||
    "dayjs": "1.8.33",
 | 
					    "dayjs": "1.8.34",
 | 
				
			||||||
    "debug": "4.1.1",
 | 
					    "debug": "4.1.1",
 | 
				
			||||||
    "ejs": "3.1.5",
 | 
					    "ejs": "3.1.5",
 | 
				
			||||||
    "electron-debug": "3.1.0",
 | 
					    "electron-debug": "3.1.0",
 | 
				
			||||||
 | 
				
			|||||||
@ -23,7 +23,8 @@ app.use(helmet({
 | 
				
			|||||||
    hidePoweredBy: false, // deactivated because electron 4.0 crashes on this right after startup
 | 
					    hidePoweredBy: false, // deactivated because electron 4.0 crashes on this right after startup
 | 
				
			||||||
    contentSecurityPolicy: {
 | 
					    contentSecurityPolicy: {
 | 
				
			||||||
        directives: {
 | 
					        directives: {
 | 
				
			||||||
            defaultSrc: ["*", "'unsafe-inline'", "'unsafe-eval'", "img-src 'self' data:"]
 | 
					            defaultSrc: ["*", "'unsafe-inline'", "'unsafe-eval'"],
 | 
				
			||||||
 | 
					            imgSrc: ["'self' data:"]
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}));
 | 
					}));
 | 
				
			||||||
 | 
				
			|||||||
@ -165,23 +165,22 @@ class TreeCache {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        for (const note of resp.notes) {
 | 
					        for (const note of resp.notes) {
 | 
				
			||||||
            if (note.type === 'search') {
 | 
					            if (note.type === 'search') {
 | 
				
			||||||
                const searchResults = await server.get('search-note/' + note.noteId);
 | 
					                const searchResultNoteIds = await server.get('search-note/' + note.noteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (!searchResults) {
 | 
					                if (!searchResultNoteIds) {
 | 
				
			||||||
                    throw new Error(`Search note ${note.noteId} failed.`);
 | 
					                    throw new Error(`Search note ${note.noteId} failed.`);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                // force to load all the notes at once instead of one by one
 | 
					                // force to load all the notes at once instead of one by one
 | 
				
			||||||
                await this.getNotes(searchResults.map(res => res.noteId));
 | 
					                await this.getNotes(searchResultNoteIds);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                const branches = resp.branches.filter(b => b.noteId === note.noteId || b.parentNoteId === note.noteId);
 | 
					                const branches = resp.branches.filter(b => b.noteId === note.noteId || b.parentNoteId === note.noteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                searchResults.forEach((result, index) => branches.push({
 | 
					                searchResultNoteIds.forEach((resultNoteId, index) => branches.push({
 | 
				
			||||||
                    // branchId should be repeatable since sometimes we reload some notes without rerendering the tree
 | 
					                    // branchId should be repeatable since sometimes we reload some notes without rerendering the tree
 | 
				
			||||||
                    branchId: "virt" + result.noteId + '-' + note.noteId,
 | 
					                    branchId: "virt" + resultNoteId + '-' + note.noteId,
 | 
				
			||||||
                    noteId: result.noteId,
 | 
					                    noteId: resultNoteId,
 | 
				
			||||||
                    parentNoteId: note.noteId,
 | 
					                    parentNoteId: note.noteId,
 | 
				
			||||||
                    prefix: this.getBranch(result.branchId).prefix,
 | 
					 | 
				
			||||||
                    notePosition: (index + 1) * 10
 | 
					                    notePosition: (index + 1) * 10
 | 
				
			||||||
                }));
 | 
					                }));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -217,7 +216,7 @@ class TreeCache {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return noteIds.map(noteId => {
 | 
					        return noteIds.map(noteId => {
 | 
				
			||||||
            if (!this.notes[noteId] && !silentNotFoundError) {
 | 
					            if (!this.notes[noteId] && !silentNotFoundError) {
 | 
				
			||||||
                console.log(`Can't find note "${noteId}"`);
 | 
					                console.trace(`Can't find note "${noteId}"`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                return null;
 | 
					                return null;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
				
			|||||||
@ -589,7 +589,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
 | 
				
			|||||||
        const note = await branch.getNote();
 | 
					        const note = await branch.getNote();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!note) {
 | 
					        if (!note) {
 | 
				
			||||||
            throw new Error(`Branch has no note ` + branch.noteId);
 | 
					            throw new Error(`Branch has no note "${branch.noteId}": ${JSON.stringify(note)}`);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const title = (branch.prefix ? (branch.prefix + " - ") : "") + note.title;
 | 
					        const title = (branch.prefix ? (branch.prefix + " - ") : "") + note.title;
 | 
				
			||||||
 | 
				
			|||||||
@ -23,7 +23,7 @@ function searchNotes(req) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function searchFromNote(req) {
 | 
					async function searchFromNote(req) {
 | 
				
			||||||
    const note = repository.getNote(req.params.noteId);
 | 
					    const note = repository.getNote(req.params.noteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!note) {
 | 
					    if (!note) {
 | 
				
			||||||
@ -44,15 +44,16 @@ function searchFromNote(req) {
 | 
				
			|||||||
        return [];
 | 
					        return [];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let noteIds;
 | 
					    let searchResultNoteIds;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
        if (json.searchString.startsWith('=')) {
 | 
					        if (json.searchString.startsWith('=')) {
 | 
				
			||||||
            const relationName = json.searchString.substr(1).trim();
 | 
					            const relationName = json.searchString.substr(1).trim();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            noteIds = searchFromRelation(note, relationName);
 | 
					            searchResultNoteIds = await searchFromRelation(note, relationName);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            noteIds = searchService.searchForNoteIds(json.searchString);
 | 
					            searchResultNoteIds = searchService.searchNotes(json.searchString)
 | 
				
			||||||
 | 
					                .map(sr => sr.noteId);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    catch (e) {
 | 
					    catch (e) {
 | 
				
			||||||
@ -62,16 +63,17 @@ function searchFromNote(req) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // we won't return search note's own noteId
 | 
					    // we won't return search note's own noteId
 | 
				
			||||||
    noteIds = noteIds.filter(noteId => noteId !== note.noteId);
 | 
					    // also don't allow root since that would force infinite cycle
 | 
				
			||||||
 | 
					    searchResultNoteIds = searchResultNoteIds.filter(resultNoteId => !['root', note.noteId].includes(resultNoteId));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (noteIds.length > 200) {
 | 
					    if (searchResultNoteIds.length > 200) {
 | 
				
			||||||
        noteIds = noteIds.slice(0, 200);
 | 
					        searchResultNoteIds = searchResultNoteIds.slice(0, 200);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return noteIds.map(noteCacheService.getNotePath).filter(res => !!res);
 | 
					    return searchResultNoteIds;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function searchFromRelation(note, relationName) {
 | 
					async function searchFromRelation(note, relationName) {
 | 
				
			||||||
    const scriptNote = note.getRelationTarget(relationName);
 | 
					    const scriptNote = note.getRelationTarget(relationName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!scriptNote) {
 | 
					    if (!scriptNote) {
 | 
				
			||||||
@ -92,7 +94,7 @@ function searchFromRelation(note, relationName) {
 | 
				
			|||||||
        return [];
 | 
					        return [];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const result = scriptService.executeNote(scriptNote, { originEntity: note });
 | 
					    const result = await scriptService.executeNote(scriptNote, { originEntity: note });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!Array.isArray(result)) {
 | 
					    if (!Array.isArray(result)) {
 | 
				
			||||||
        log.info(`Result from ${scriptNote.noteId} is not an array.`);
 | 
					        log.info(`Result from ${scriptNote.noteId} is not an array.`);
 | 
				
			||||||
 | 
				
			|||||||
@ -92,7 +92,7 @@ function copyChildAttributes(parentNote, childNote) {
 | 
				
			|||||||
 * - {integer} notePosition - default is last existing notePosition in a parent + 10
 | 
					 * - {integer} notePosition - default is last existing notePosition in a parent + 10
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @param params
 | 
					 * @param params
 | 
				
			||||||
 * @return {Promise<{note: Note, branch: Branch}>}
 | 
					 * @return {{note: Note, branch: Branch}}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function createNewNote(params) {
 | 
					function createNewNote(params) {
 | 
				
			||||||
    const parentNote = repository.getNote(params.parentNoteId);
 | 
					    const parentNote = repository.getNote(params.parentNoteId);
 | 
				
			||||||
 | 
				
			|||||||
@ -14,7 +14,7 @@ const utils = require('../../utils.js');
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @param {Expression} expression
 | 
					 * @param {Expression} expression
 | 
				
			||||||
 * @return {Promise<SearchResult[]>}
 | 
					 * @return {SearchResult[]}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function findNotesWithExpression(expression) {
 | 
					function findNotesWithExpression(expression) {
 | 
				
			||||||
    const hoistedNote = noteCache.notes[hoistedNoteService.getHoistedNoteId()];
 | 
					    const hoistedNote = noteCache.notes[hoistedNoteService.getHoistedNoteId()];
 | 
				
			||||||
@ -67,7 +67,7 @@ function parseQueryToExpression(query, parsingContext) {
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * @param {string} query
 | 
					 * @param {string} query
 | 
				
			||||||
 * @param {ParsingContext} parsingContext
 | 
					 * @param {ParsingContext} parsingContext
 | 
				
			||||||
 * @return {Promise<SearchResult[]>}
 | 
					 * @return {SearchResult[]}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function findNotesWithQuery(query, parsingContext) {
 | 
					function findNotesWithQuery(query, parsingContext) {
 | 
				
			||||||
    const expression = parseQueryToExpression(query, parsingContext);
 | 
					    const expression = parseQueryToExpression(query, parsingContext);
 | 
				
			||||||
@ -79,6 +79,9 @@ function findNotesWithQuery(query, parsingContext) {
 | 
				
			|||||||
    return findNotesWithExpression(expression);
 | 
					    return findNotesWithExpression(expression);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @return {SearchResult[]}
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
function searchNotes(query) {
 | 
					function searchNotes(query) {
 | 
				
			||||||
    if (!query.trim().length) {
 | 
					    if (!query.trim().length) {
 | 
				
			||||||
        return [];
 | 
					        return [];
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user