Forráskód Böngészése

fix: add :feature/enable-search-remove-accents

maxweilun1989 3 éve
szülő
commit
15a0f19a82

+ 4 - 4
src/main/frontend/components/search.cljs

@@ -29,8 +29,8 @@
     content
     (when (and content q)
       (let [q-words (string/split q #" ")
-            lc-content (util/search-normalize content)
-            lc-q (util/search-normalize q)]
+            lc-content (util/search-normalize content (state/enable-search-remove-accents?))
+            lc-q (util/search-normalize q (state/enable-search-remove-accents?))]
         (if (and (string/includes? lc-content lc-q)
                  (not (util/safe-re-find #" " q)))
           (let [i (string/index-of lc-content lc-q)
@@ -46,8 +46,8 @@
                                 result []]
                            (if (and (seq words) content)
                              (let [word (first words)
-                                   lc-word (util/search-normalize word)
-                                   lc-content (util/search-normalize content)]
+                                   lc-word (util/search-normalize word (state/enable-search-remove-accents?))
+                                   lc-content (util/search-normalize content (state/enable-search-remove-accents?))]
                                (if-let [i (string/index-of lc-content lc-word)]
                                  (recur (rest words)
                                         (subs content (+ i (count word)))

+ 6 - 6
src/main/frontend/search.cljs

@@ -77,20 +77,20 @@
 (defn fuzzy-search
   [data query & {:keys [limit extract-fn]
                  :or {limit 20}}]
-  (let [query (util/search-normalize query)]
+  (let [query (util/search-normalize query (state/enable-search-remove-accents?))]
     (->> (take limit
                (sort-by :score (comp - compare)
                         (filter #(< 0 (:score %))
                                 (for [item data]
                                   (let [s (str (if extract-fn (extract-fn item) item))]
                                     {:data item
-                                     :score (score query (util/search-normalize s))})))))
+                                     :score (score query (util/search-normalize s (state/enable-search-remove-accents?)))})))))
          (map :data))))
 
 (defn block-search
   [repo q option]
   (when-let [engine (get-engine repo)]
-    (let [q (util/search-normalize q)
+    (let [q (util/search-normalize q (state/enable-search-remove-accents?))
           q (if (util/electron?) q (escape-str q))]
       (when-not (string/blank? q)
         (protocol/query engine q option)))))
@@ -111,8 +111,8 @@
           (if (seq coll')
             (rest coll')
             (reduced false))))
-      (seq (util/search-normalize match))
-      (seq (util/search-normalize q))))))
+      (seq (util/search-normalize match (state/enable-search-remove-accents?)))
+      (seq (util/search-normalize q (state/enable-search-remove-accents?)))))))
 
 (defn page-search
   "Return a list of page names that match the query"
@@ -120,7 +120,7 @@
    (page-search q 10))
   ([q limit]
    (when-let [repo (state/get-current-repo)]
-     (let [q (util/search-normalize q)
+     (let [q (util/search-normalize q (state/enable-search-remove-accents?))
            q (clean-str q)]
        (when-not (string/blank? q)
          (let [indice (or (get-in @indices [repo :pages])

+ 2 - 2
src/main/frontend/search/db.cljs

@@ -13,7 +13,7 @@
 (defn block->index
   "Convert a block to the index for searching"
   [{:block/keys [uuid page content] :as block}]
-  (when-let [content (util/search-normalize content)]
+  (when-let [content (util/search-normalize content (state/enable-search-remove-accents?))]
     {:id (:db/id block)
      :uuid (str uuid)
      :page page
@@ -42,7 +42,7 @@
     indice))
 
 (defn original-page-name->index
-  [p] {:name (util/search-normalize p)
+  [p] {:name (util/search-normalize p (state/enable-search-remove-accents?))
        :original-name p})
 
 (defn make-pages-indice!

+ 5 - 0
src/main/frontend/state.cljs

@@ -1691,3 +1691,8 @@
 (defn unlinked-dir?
   [dir]
   (contains? (:file/unlinked-dirs @state) dir))
+
+(defn enable-search-remove-accents?
+  []
+  (:feature/enable-search-remove-accents?
+    (get (sub-config) (get-current-repo))))

+ 5 - 2
src/main/frontend/util.cljc

@@ -917,8 +917,11 @@
 #?(:cljs
    (defn search-normalize
      "Normalize string for searching (loose)"
-     [s]
-     (removeAccents (.normalize (string/lower-case s) "NFKC"))))
+     [s remove-accents?]
+     (let [normalize-str (.normalize (string/lower-case s) "NFKC")]
+      (if remove-accents?
+        (removeAccents  normalize-str)
+        normalize-str))))
 
 #?(:cljs
    (defn file-name-sanity

+ 3 - 0
templates/config.edn

@@ -27,6 +27,9 @@
  ;; Enable Block timestamp
  :feature/enable-block-timestamps? false
 
+ ;; Enable remove accents when search
+ :feature/enable-search-remove-accents? true
+
  ;; Disable Built-in Scheduled and deadline Query
  ;; :feature/disable-scheduled-and-deadline-query? true