mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 20:06:08 +01:00 
			
		
		
		
	added IN operator to search, closes #534
This commit is contained in:
		@@ -67,7 +67,7 @@ module.exports = function(filters, selectedColumns = 'notes.*') {
 | 
				
			|||||||
    const params = [];
 | 
					    const params = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (const filter of filters) {
 | 
					    for (const filter of filters) {
 | 
				
			||||||
        if (['isarchived', 'orderby', 'limit'].includes(filter.name.toLowerCase())) {
 | 
					        if (['isarchived', 'in', 'orderby', 'limit'].includes(filter.name.toLowerCase())) {
 | 
				
			||||||
            continue; // these are not real filters
 | 
					            continue; // these are not real filters
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -255,6 +255,25 @@ function isArchived(noteId) {
 | 
				
			|||||||
    return isNotePathArchived(notePath);
 | 
					    return isNotePathArchived(notePath);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @param {string} noteId
 | 
				
			||||||
 | 
					 * @param {string} ancestorNoteId
 | 
				
			||||||
 | 
					 * @return {boolean} - true if given noteId has ancestorNoteId in any of its paths (even archived)
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function isInAncestor(noteId, ancestorNoteId) {
 | 
				
			||||||
 | 
					    if (ancestorNoteId === noteId) { // special case
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (const parentNoteId of childToParent[noteId] || []) {
 | 
				
			||||||
 | 
					        if (isInAncestor(parentNoteId, ancestorNoteId)) {
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getNoteTitleFromPath(notePath) {
 | 
					function getNoteTitleFromPath(notePath) {
 | 
				
			||||||
    const pathArr = notePath.split("/");
 | 
					    const pathArr = notePath.split("/");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -529,6 +548,7 @@ module.exports = {
 | 
				
			|||||||
    getNoteTitleFromPath,
 | 
					    getNoteTitleFromPath,
 | 
				
			||||||
    isAvailable,
 | 
					    isAvailable,
 | 
				
			||||||
    isArchived,
 | 
					    isArchived,
 | 
				
			||||||
 | 
					    isInAncestor,
 | 
				
			||||||
    load,
 | 
					    load,
 | 
				
			||||||
    findSimilarNotes
 | 
					    findSimilarNotes
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
@@ -35,6 +35,20 @@ async function searchForNoteIds(searchString) {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const isInFilter = filters.find(filter => filter.name.toLowerCase() === 'in');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (isInFilter) {
 | 
				
			||||||
 | 
					            if (isInFilter.operator === '=') {
 | 
				
			||||||
 | 
					                noteIds = noteIds.filter(noteId => noteCacheService.isInAncestor(noteId, isInFilter.value));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else if (isInFilter.operator === '!=') {
 | 
				
			||||||
 | 
					                noteIds = noteIds.filter(noteId => !noteCacheService.isInAncestor(noteId, isInFilter.value));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else {
 | 
				
			||||||
 | 
					                throw new Error(`Unrecognized isIn operator ${isInFilter.operator}`);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const limitFilter = filters.find(filter => filter.name.toLowerCase() === 'limit');
 | 
					        const limitFilter = filters.find(filter => filter.name.toLowerCase() === 'limit');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (limitFilter) {
 | 
					        if (limitFilter) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user