feat(jump-to-note): ignore ~internalLink (closes #713)

This commit is contained in:
Elian Doran 2024-12-14 02:07:00 +02:00
parent 9494362fb0
commit 43567525e3
No known key found for this signature in database
3 changed files with 15 additions and 2 deletions

View File

@ -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) {

View File

@ -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))) {

View File

@ -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;