From 43567525e368f58b48f77d79f4494c4e03799f4e Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 14 Dec 2024 02:07:00 +0200 Subject: [PATCH] feat(jump-to-note): ignore ~internalLink (closes #713) --- src/services/search/search_context.ts | 3 +++ src/services/search/services/search.ts | 12 ++++++++++-- src/services/search/services/types.ts | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/services/search/search_context.ts b/src/services/search/search_context.ts index c024be9a7..17e75d795 100644 --- a/src/services/search/search_context.ts +++ b/src/services/search/search_context.ts @@ -9,6 +9,8 @@ class SearchContext { includeArchivedNotes: boolean; includeHiddenNotes: boolean; ignoreHoistedNote: boolean; + /** Whether to ignore certain attributes from the search such as ~internalLink. */ + ignoreInternalAttributes: boolean; ancestorNoteId?: string; ancestorDepth?: string; orderBy?: string; @@ -28,6 +30,7 @@ class SearchContext { this.includeArchivedNotes = !!params.includeArchivedNotes; this.includeHiddenNotes = !!params.includeHiddenNotes; this.ignoreHoistedNote = !!params.ignoreHoistedNote; + this.ignoreInternalAttributes = !!params.ignoreInternalAttributes; this.ancestorNoteId = params.ancestorNoteId; if (!this.ancestorNoteId && !this.ignoreHoistedNote) { diff --git a/src/services/search/services/search.ts b/src/services/search/services/search.ts index 28b2350c2..1b941adda 100644 --- a/src/services/search/services/search.ts +++ b/src/services/search/services/search.ts @@ -346,6 +346,7 @@ function searchNotesForAutocomplete(query: string, fastSearch: boolean = true) { includeArchivedNotes: false, includeHiddenNotes: true, fuzzyAttributeSearch: true, + ignoreInternalAttributes: true, ancestorNoteId: hoistedNoteService.isHoistedInHiddenSubtree() ? 'root' : hoistedNoteService.getHoistedNoteId() @@ -355,7 +356,7 @@ function searchNotesForAutocomplete(query: string, fastSearch: boolean = true) { const trimmed = allSearchResults.slice(0, 200); - highlightSearchResults(trimmed, searchContext.highlightedTokens); + highlightSearchResults(trimmed, searchContext.highlightedTokens, searchContext.ignoreInternalAttributes); return trimmed.map(result => { return { @@ -367,7 +368,10 @@ function searchNotesForAutocomplete(query: string, fastSearch: boolean = true) { }); } -function highlightSearchResults(searchResults: SearchResult[], highlightedTokens: string[]) { +/** + * @param ignoreInternalAttributes whether to ignore certain attributes from the search such as ~internalLink. + */ +function highlightSearchResults(searchResults: SearchResult[], highlightedTokens: string[], ignoreInternalAttributes = false) { highlightedTokens = Array.from(new Set(highlightedTokens)); // we remove < signs because they can cause trouble in matching and overwriting existing highlighted chunks @@ -395,6 +399,10 @@ function highlightSearchResults(searchResults: SearchResult[], highlightedTokens } for (const attr of note.getAttributes()) { + if (attr.type === "relation" && attr.name === "internalLink" && ignoreInternalAttributes) { + continue; + } + if (highlightedTokens.find(token => utils.normalize(attr.name).includes(token) || utils.normalize(attr.value).includes(token))) { diff --git a/src/services/search/services/types.ts b/src/services/search/services/types.ts index 2b12a3c65..47e641d37 100644 --- a/src/services/search/services/types.ts +++ b/src/services/search/services/types.ts @@ -12,6 +12,8 @@ export interface SearchParams { includeArchivedNotes?: boolean; includeHiddenNotes?: boolean; ignoreHoistedNote?: boolean; + /** Whether to ignore certain attributes from the search such as ~internalLink. */ + ignoreInternalAttributes?: boolean; ancestorNoteId?: string; ancestorDepth?: string; orderBy?: string;