From 03ccac2872822442b4e11457e1c3452167a3f639 Mon Sep 17 00:00:00 2001
From: Amir Pourmand <pourmand1376@gmail.com>
Date: Wed, 17 Sep 2025 22:39:30 +0000
Subject: [PATCH] feat: Update FlexSearch and Add Support for All Languages (#2108)
---
quartz/components/scripts/search.inline.ts | 16 +++++++++++-----
1 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/quartz/components/scripts/search.inline.ts b/quartz/components/scripts/search.inline.ts
index 28d47e9..6a84a50 100644
--- a/quartz/components/scripts/search.inline.ts
+++ b/quartz/components/scripts/search.inline.ts
@@ -1,4 +1,4 @@
-import FlexSearch from "flexsearch"
+import FlexSearch, { DefaultDocumentSearchResults } from "flexsearch"
import { ContentDetails } from "../../plugins/emitters/contentIndex"
import { registerEscapeHandler, removeAllChildren } from "./util"
import { FullSlug, normalizeRelativeURLs, resolveRelative } from "../../util/path"
@@ -9,15 +9,21 @@
title: string
content: string
tags: string[]
+ [key: string]: any
}
// Can be expanded with things like "term" in the future
type SearchType = "basic" | "tags"
let searchType: SearchType = "basic"
let currentSearchTerm: string = ""
-const encoder = (str: string) => str.toLowerCase().split(/([^a-z]|[^\x00-\x7F])/)
+const encoder = (str: string) => {
+ return str
+ .toLowerCase()
+ .split(/\s+/)
+ .filter((token) => token.length > 0)
+}
+
let index = new FlexSearch.Document<Item>({
- charset: "latin:extra",
encode: encoder,
document: {
id: "id",
@@ -397,7 +403,7 @@
searchLayout.classList.toggle("display-results", currentSearchTerm !== "")
searchType = currentSearchTerm.startsWith("#") ? "tags" : "basic"
- let searchResults: FlexSearch.SimpleDocumentSearchResultSetUnit[]
+ let searchResults: DefaultDocumentSearchResults<Item>
if (searchType === "tags") {
currentSearchTerm = currentSearchTerm.substring(1).trim()
const separatorIndex = currentSearchTerm.indexOf(" ")
@@ -410,7 +416,7 @@
// return at least 10000 documents, so it is enough to filter them by tag (implemented in flexsearch)
limit: Math.max(numSearchResults, 10000),
index: ["title", "content"],
- tag: tag,
+ tag: { tags: tag },
})
for (let searchResult of searchResults) {
searchResult.result = searchResult.result.slice(0, numSearchResults)
--
Gitblit v1.10.0