fix(search): resolve issue with autocomplete with search performance enhancements

This commit is contained in:
perfectra1n
2026-03-18 09:46:24 -07:00
parent da3d71d21e
commit 5718631889
4 changed files with 12 additions and 7 deletions

View File

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

View File

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

View File

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

View File

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