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