mirror of
https://github.com/zadam/trilium.git
synced 2026-05-07 19:06:18 +02:00
fix(search): resolve issue with autocomplete with search performance enhancements
This commit is contained in:
@@ -96,10 +96,10 @@ class NoteFlatTextExp extends Expression {
|
||||
|
||||
const candidateNotes = this.getCandidateNotes(inputNoteSet, searchContext);
|
||||
|
||||
// Fast path for single-token searches with a limit (e.g. autocomplete):
|
||||
// Fast path for single-token autocomplete searches:
|
||||
// Skip the expensive recursive parent walk and just use getBestNotePath().
|
||||
// The flat text already matched, so we know the token is present.
|
||||
if (this.tokens.length === 1 && searchContext.limit) {
|
||||
if (this.tokens.length === 1 && searchContext.autocomplete) {
|
||||
for (const note of candidateNotes) {
|
||||
if (!resultNoteSet.hasNoteId(note.noteId)) {
|
||||
const notePath = note.getBestNotePath();
|
||||
|
||||
@@ -18,6 +18,8 @@ class SearchContext {
|
||||
debug?: boolean;
|
||||
debugInfo: {} | null;
|
||||
fuzzyAttributeSearch: boolean;
|
||||
/** When true, skip the two-phase fuzzy fallback and use the single-token fast path. */
|
||||
autocomplete: boolean;
|
||||
enableFuzzyMatching: boolean; // Controls whether fuzzy matching is enabled for this search phase
|
||||
highlightedTokens: string[];
|
||||
originalQuery: string;
|
||||
@@ -46,6 +48,7 @@ class SearchContext {
|
||||
this.debug = params.debug;
|
||||
this.debugInfo = null;
|
||||
this.fuzzyAttributeSearch = !!params.fuzzyAttributeSearch;
|
||||
this.autocomplete = !!params.autocomplete;
|
||||
this.enableFuzzyMatching = true; // Default to true for backward compatibility
|
||||
this.highlightedTokens = [];
|
||||
this.originalQuery = "";
|
||||
|
||||
@@ -248,10 +248,10 @@ function findResultsWithExpression(expression: Expression, searchContext: Search
|
||||
return performSearch(expression, searchContext, false);
|
||||
}
|
||||
|
||||
// For limited searches (e.g. autocomplete), skip the expensive two-phase
|
||||
// fuzzy fallback. The user is typing and will refine their query — exact
|
||||
// matching is sufficient and avoids a second full scan of all notes.
|
||||
if (searchContext.limit) {
|
||||
// For autocomplete searches, skip the expensive two-phase fuzzy fallback.
|
||||
// The user is typing and will refine their query — exact matching is
|
||||
// sufficient and avoids a second full scan of all notes.
|
||||
if (searchContext.autocomplete) {
|
||||
return performSearch(expression, searchContext, false);
|
||||
}
|
||||
|
||||
@@ -645,7 +645,7 @@ function searchNotesForAutocomplete(query: string, fastSearch: boolean = true) {
|
||||
fuzzyAttributeSearch: true,
|
||||
ignoreInternalAttributes: true,
|
||||
ancestorNoteId: hoistedNoteService.isHoistedInHiddenSubtree() ? "root" : hoistedNoteService.getHoistedNoteId(),
|
||||
limit: 200
|
||||
autocomplete: true
|
||||
});
|
||||
|
||||
const allSearchResults = findResultsWithQuery(query, searchContext);
|
||||
|
||||
@@ -21,4 +21,6 @@ export interface SearchParams {
|
||||
limit?: number | null;
|
||||
debug?: boolean;
|
||||
fuzzyAttributeSearch?: boolean;
|
||||
/** When true, skip the two-phase fuzzy fallback and use the single-token fast path. */
|
||||
autocomplete?: boolean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user