This commit is contained in:
Mega Yu
2026-04-28 16:40:55 +08:00
parent a00fb39413
commit b5bcea3eb5
2 changed files with 9 additions and 7 deletions

View File

@@ -1,11 +1,12 @@
(ns frontend.common.search-fuzzy
"fuzzy search. Used by frontend and worker namespaces"
(:require ["remove-accents$default" :as removeAccents]
(:require ["remove-accents" :refer [remove]]
["tiny-pinyin" :as tp]
[cljs-bean.core :as bean]
[clojure.string :as string]))
(def MAX-STRING-LENGTH 1000.0)
(def strip-accents remove)
(defn clean-str
[s]
@@ -37,7 +38,7 @@
(let [s' (if lower-case? (string/lower-case s) s)
normalize-str (.normalize s' "NFKC")]
(if remove-accents?
(removeAccents normalize-str)
(strip-accents normalize-str)
normalize-str))))
(defn score
@@ -104,7 +105,7 @@
(for [item data]
(let [strings (->> extract-fns
(map (fn [f] (str (f item))))
(remove string/blank?))
(cljs.core/remove string/blank?))
best-score (if (seq strings)
(apply max (map #(score query %) strings))
0)]
@@ -112,7 +113,6 @@
:score best-score})))))
(map :data)))
(defn- zh-simplified-char?
"True for characters in the CJK Unified Ideographs blocks
used by Simplified Chinese."
@@ -135,7 +135,7 @@
(when (seq seg)
(->> (string/replace seg #"[^a-zA-Z0-9 ]" "")
(#(string/split % #"\s+"))
(remove string/blank?)
(cljs.core/remove string/blank?)
(map #(string/lower-case (subs % 0 1))))))
(defn hanzi->initials

View File

@@ -1,6 +1,6 @@
(ns frontend.components.cmdk.list-item
(:require
["remove-accents$default" :as removeAccents]
["remove-accents" :refer [remove]]
[clojure.string :as string]
[frontend.components.icon :as icon-component]
[frontend.handler.block :as block-handler]
@@ -8,6 +8,8 @@
[logseq.shui.ui :as shui]
[rum.core :as rum]))
(def strip-accents remove)
(defn- to-string [input]
(cond
(string? input) input
@@ -22,7 +24,7 @@
(cond-> (to-string text)
;; :lower-case (string/lower-case)
:normalize (.normalize "NFKC")
(:feature/enable-search-remove-accents? app-config) (removeAccents)))
(:feature/enable-search-remove-accents? app-config) (strip-accents)))
(defn highlight-query* [app-config query text]
(cond