Skip to content

Build your personal knowledge base with Trilium Notes

feat(autocomplete): toggle for fuzzy matching (closes #8360)

Elian Doran6e90a4168e56
diff --git a/CLAUDE.md b/CLAUDE.md
index 1b90b02881..a395f985bf 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -162,8 +162,9 @@ Trilium provides powerful user scripting capabilities:
- To add a new user preference:
1. Add the option type to `OptionDefinitions` in `packages/commons/src/lib/options_interface.ts`
2. Add a default value in `apps/server/src/services/options_init.ts` in the `defaultOptions` array
- 3. **Whitelist the option** in `apps/server/src/routes/api/options.ts` by adding it to `ALLOWED_OPTIONS` (required for client updates)
- 4. Use `useTriliumOption("optionName")` hook in React components to read/write the option
+ 3. **Whitelist the option** in `apps/server/src/routes/api/options.ts` by adding it to the `ALLOWED_OPTIONS` array — **without this, the API will reject changes with "Option 'X' is not allowed to be changed"**
+ 4. If the option should be user-editable in the UI, add a control in the appropriate settings component (e.g., `apps/client/src/widgets/type_widgets/options/other.tsx`) and a translation key in `apps/client/src/translations/en/translation.json`
+ 5. Use `useTriliumOption("optionName")` hook in React components to read/write the option
- Available hooks: `useTriliumOption` (string), `useTriliumOptionBool`, `useTriliumOptionInt`, `useTriliumOptionJson`
- See `docs/Developer Guide/Developer Guide/Concepts/Options/Creating a new option.md` for detailed documentation
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 2c1e1ae19a..abc3de3de4 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1326,7 +1326,8 @@
},
"search": {
"title": "Search",
- "enable_fuzzy_matching": "Enable fuzzy matching in search (matches similar words when exact matches are insufficient)"
+ "enable_fuzzy_matching": "Enable fuzzy matching in search (matches similar words when exact matches are insufficient)",
+ "enable_autocomplete_fuzzy": "Enable fuzzy matching for autocomplete (slower, but tolerates typos while typing)"
},
"search_engine": {
"title": "Search Engine",
diff --git a/apps/client/src/widgets/type_widgets/options/other.tsx b/apps/client/src/widgets/type_widgets/options/other.tsx
index 8cb99bace4..b75c81b711 100644
--- a/apps/client/src/widgets/type_widgets/options/other.tsx
+++ b/apps/client/src/widgets/type_widgets/options/other.tsx
@@ -39,6 +39,7 @@ export default function OtherSettings() {
function SearchSettings() {
const [ fuzzyEnabled, setFuzzyEnabled ] = useTriliumOptionBool("searchEnableFuzzyMatching");
+ const [ autocompleteFuzzy, setAutocompleteFuzzy ] = useTriliumOptionBool("searchAutocompleteFuzzy");
return (
<OptionsSection title={t("search.title")}>
@@ -48,6 +49,12 @@ function SearchSettings() {
currentValue={fuzzyEnabled}
onChange={setFuzzyEnabled}
/>
+ <FormCheckbox
+ name="search-autocomplete-fuzzy"
+ label={t("search.enable_autocomplete_fuzzy")}
+ currentValue={autocompleteFuzzy}
+ onChange={setAutocompleteFuzzy}
+ />
</OptionsSection>
);
}
diff --git a/apps/server/src/routes/api/options.ts b/apps/server/src/routes/api/options.ts
index 384c975eba..9be9ba0670 100644
--- a/apps/server/src/routes/api/options.ts
+++ b/apps/server/src/routes/api/options.ts
@@ -100,6 +100,7 @@ const ALLOWED_OPTIONS = new Set<OptionNames>([
"backgroundEffects",
"allowedHtmlTags",
"searchEnableFuzzyMatching",
+ "searchAutocompleteFuzzy",
"redirectBareDomain",
"showLoginInShareTheme",
"splitEditorOrientation",
diff --git a/apps/server/src/services/options_init.ts b/apps/server/src/services/options_init.ts
index 9ac33d4e31..4bff15d91e 100644
--- a/apps/server/src/services/options_init.ts
+++ b/apps/server/src/services/options_init.ts
@@ -236,6 +236,7 @@ const defaultOptions: DefaultOption[] = [
// Search settings
{ name: "searchEnableFuzzyMatching", value: "true", isSynced: true },
+ { name: "searchAutocompleteFuzzy", value: "false", isSynced: true },
// Share settings
{ name: "redirectBareDomain", value: "false", isSynced: true },
diff --git a/apps/server/src/services/search/services/search.ts b/apps/server/src/services/search/services/search.ts
index 226c809d7d..660c46119b 100644
--- a/apps/server/src/services/search/services/search.ts
+++ b/apps/server/src/services/search/services/search.ts
@@ -17,6 +17,7 @@ import type Expression from "../expressions/expression.js";
import sql from "../../sql.js";
import scriptService from "../../script.js";
import protectedSessionService from "../../protected_session.js";
+import optionService from "../../options.js";
export interface SearchNoteResult {
searchResultNoteIds: string[];
@@ -248,11 +249,11 @@ function findResultsWithExpression(expression: Expression, searchContext: Search
return performSearch(expression, searchContext, false);
}
- // 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.
+ // For autocomplete searches, use the dedicated autocomplete fuzzy option.
+ // Default is off for faster response; users can enable if they want typo tolerance.
if (searchContext.autocomplete) {
- return performSearch(expression, searchContext, false);
+ const autocompleteFuzzy = optionService.getOptionBool("searchAutocompleteFuzzy");
+ return performSearch(expression, searchContext, autocompleteFuzzy);
}
// Phase 1: Try exact matches first (without fuzzy matching)
diff --git a/packages/commons/src/lib/options_interface.ts b/packages/commons/src/lib/options_interface.ts
index d57217712e..a00666677a 100644
--- a/packages/commons/src/lib/options_interface.ts
+++ b/packages/commons/src/lib/options_interface.ts
@@ -138,6 +138,8 @@ export interface OptionDefinitions extends KeyboardShortcutsOptions<KeyboardActi
// Search settings
/** Whether fuzzy matching is enabled in search (matches similar words when exact matches are insufficient). */
searchEnableFuzzyMatching: boolean;
+ /** Whether fuzzy matching is enabled for autocomplete (typing in search bar). Disabled by default for faster response. */
+ searchAutocompleteFuzzy: boolean;
// Share settings
redirectBareDomain: boolean;