Skip to content

Build your personal knowledge base with Trilium Notes

feat(settings): also allow for fuzzy searching to just be disabled

perfectra1nf23a7b484292
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index fdd6f9fb2d..f9ba8f8743 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1292,6 +1292,10 @@
"erase_excess_revision_snapshots": "Erase excess revision snapshots now",
"erase_excess_revision_snapshots_prompt": "Excess revision snapshots have been erased."
},
+ "search": {
+ "title": "Search",
+ "enable_fuzzy_matching": "Enable fuzzy matching in search (matches similar words when exact matches are insufficient)"
+ },
"search_engine": {
"title": "Search Engine",
"custom_search_engine_info": "Custom search engine requires both a name and a URL to be set. If either of these is not set, DuckDuckGo will be used as the default 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 e6813f8d2b..8cb99bace4 100644
--- a/apps/client/src/widgets/type_widgets/options/other.tsx
+++ b/apps/client/src/widgets/type_widgets/options/other.tsx
@@ -21,6 +21,7 @@ import TimeSelector from "./components/TimeSelector";
export default function OtherSettings() {
return (
<>
+ <SearchSettings />
{isElectron() && <>
<SearchEngineSettings />
<TrayOptionsSettings />
@@ -36,6 +37,21 @@ export default function OtherSettings() {
);
}
+function SearchSettings() {
+ const [ fuzzyEnabled, setFuzzyEnabled ] = useTriliumOptionBool("searchEnableFuzzyMatching");
+
+ return (
+ <OptionsSection title={t("search.title")}>
+ <FormCheckbox
+ name="search-fuzzy-matching"
+ label={t("search.enable_fuzzy_matching")}
+ currentValue={fuzzyEnabled}
+ onChange={setFuzzyEnabled}
+ />
+ </OptionsSection>
+ );
+}
+
function SearchEngineSettings() {
const [ customSearchEngineName, setCustomSearchEngineName ] = useTriliumOption("customSearchEngineName");
const [ customSearchEngineUrl, setCustomSearchEngineUrl ] = useTriliumOption("customSearchEngineUrl");
diff --git a/apps/server/src/routes/api/options.ts b/apps/server/src/routes/api/options.ts
index bb6ffb00d6..049a898fca 100644
--- a/apps/server/src/routes/api/options.ts
+++ b/apps/server/src/routes/api/options.ts
@@ -97,6 +97,7 @@ const ALLOWED_OPTIONS = new Set<OptionNames>([
"layoutOrientation",
"backgroundEffects",
"allowedHtmlTags",
+ "searchEnableFuzzyMatching",
"redirectBareDomain",
"showLoginInShareTheme",
"splitEditorOrientation",
diff --git a/apps/server/src/services/options_init.ts b/apps/server/src/services/options_init.ts
index a49672019d..17ea5a1f0b 100644
--- a/apps/server/src/services/options_init.ts
+++ b/apps/server/src/services/options_init.ts
@@ -198,6 +198,9 @@ const defaultOptions: DefaultOption[] = [
isSynced: true
},
+ // Search settings
+ { name: "searchEnableFuzzyMatching", value: "true", isSynced: true },
+
// Share settings
{ name: "redirectBareDomain", value: "false", isSynced: true },
{ name: "showLoginInShareTheme", value: "false", isSynced: true },
diff --git a/apps/server/src/services/search/search_context.ts b/apps/server/src/services/search/search_context.ts
index 55d4df5d2f..79b0b6db3d 100644
--- a/apps/server/src/services/search/search_context.ts
+++ b/apps/server/src/services/search/search_context.ts
@@ -1,6 +1,7 @@
"use strict";
import hoistedNoteService from "../hoisted_note.js";
+import optionService from "../options.js";
import type { SearchParams } from "./services/types.js";
class SearchContext {
@@ -49,7 +50,11 @@ class SearchContext {
this.debugInfo = null;
this.fuzzyAttributeSearch = !!params.fuzzyAttributeSearch;
this.autocomplete = !!params.autocomplete;
- this.enableFuzzyMatching = true; // Default to true for backward compatibility
+ try {
+ this.enableFuzzyMatching = optionService.getOptionBool("searchEnableFuzzyMatching");
+ } catch {
+ this.enableFuzzyMatching = true; // Default to true if option not yet initialized
+ }
this.highlightedTokens = [];
this.originalQuery = "";
this.fulltextQuery = ""; // complete fulltext part
diff --git a/packages/commons/src/lib/options_interface.ts b/packages/commons/src/lib/options_interface.ts
index 5582df79d2..6e36ebd7a3 100644
--- a/packages/commons/src/lib/options_interface.ts
+++ b/packages/commons/src/lib/options_interface.ts
@@ -134,6 +134,10 @@ export interface OptionDefinitions extends KeyboardShortcutsOptions<KeyboardActi
backgroundEffects: boolean;
newLayout: boolean;
+ // Search settings
+ /** Whether fuzzy matching is enabled in search (matches similar words when exact matches are insufficient). */
+ searchEnableFuzzyMatching: boolean;
+
// Share settings
redirectBareDomain: boolean;
showLoginInShareTheme: boolean;