Skip to content

Build your personal knowledge base with Trilium Notes

feat(search): add user option to enable/disable FTS5 content index

perfectra1n24a01aefe2f6
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index f9ba8f8743..5232fa1dc1 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1294,7 +1294,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_fts5": "Use content index for faster full-text search (applies on next search)"
},
"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..c16fffc891 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 [ fts5Enabled, setFts5Enabled ] = useTriliumOptionBool("searchEnableFts5");
return (
<OptionsSection title={t("search.title")}>
@@ -48,6 +49,12 @@ function SearchSettings() {
currentValue={fuzzyEnabled}
onChange={setFuzzyEnabled}
/>
+ <FormCheckbox
+ name="search-fts5"
+ label={t("search.enable_fts5")}
+ currentValue={fts5Enabled}
+ onChange={setFts5Enabled}
+ />
</OptionsSection>
);
}
diff --git a/apps/server/src/routes/api/options.ts b/apps/server/src/routes/api/options.ts
index 049a898fca..5491fbf31e 100644
--- a/apps/server/src/routes/api/options.ts
+++ b/apps/server/src/routes/api/options.ts
@@ -98,6 +98,7 @@ const ALLOWED_OPTIONS = new Set<OptionNames>([
"backgroundEffects",
"allowedHtmlTags",
"searchEnableFuzzyMatching",
+ "searchEnableFts5",
"redirectBareDomain",
"showLoginInShareTheme",
"splitEditorOrientation",
diff --git a/apps/server/src/services/options_init.ts b/apps/server/src/services/options_init.ts
index 17ea5a1f0b..de22bbaafd 100644
--- a/apps/server/src/services/options_init.ts
+++ b/apps/server/src/services/options_init.ts
@@ -200,6 +200,7 @@ const defaultOptions: DefaultOption[] = [
// Search settings
{ name: "searchEnableFuzzyMatching", value: "true", isSynced: true },
+ { name: "searchEnableFts5", value: "true", isSynced: true },
// Share settings
{ name: "redirectBareDomain", value: "false", isSynced: true },
diff --git a/apps/server/src/services/search/expressions/note_content_fulltext.ts b/apps/server/src/services/search/expressions/note_content_fulltext.ts
index 86aa40e36a..f2e0122d32 100644
--- a/apps/server/src/services/search/expressions/note_content_fulltext.ts
+++ b/apps/server/src/services/search/expressions/note_content_fulltext.ts
@@ -107,6 +107,14 @@ class NoteContentFulltextExp extends Expression {
* Whether this operator can be served by FTS5.
*/
private canUseFts(): boolean {
+ try {
+ const optionService = require("../../options.js").default;
+ if (!optionService.getOptionBool("searchEnableFts5")) {
+ return false;
+ }
+ } catch {
+ // Option not available yet — allow FTS
+ }
return ["=", "!=", "*=*"].includes(this.operator);
}
diff --git a/packages/commons/src/lib/options_interface.ts b/packages/commons/src/lib/options_interface.ts
index 6e36ebd7a3..555fd20a5b 100644
--- a/packages/commons/src/lib/options_interface.ts
+++ b/packages/commons/src/lib/options_interface.ts
@@ -137,6 +137,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 to use FTS5 index for content search (faster but requires index build). */
+ searchEnableFts5: boolean;
// Share settings
redirectBareDomain: boolean;