Pārlūkot izejas kodu

fix(mobile): build search index with simpler preprocessing rules

See-also: #10771
Andelf 2 gadi atpakaļ
vecāks
revīzija
402ee7870d
1 mainītis faili ar 19 papildinājumiem un 2 dzēšanām
  1. 19 2
      src/main/frontend/search/db.cljs

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

@@ -20,8 +20,10 @@
   (some-> content
   (some-> content
           (util/search-normalize (state/enable-search-remove-accents?))))
           (util/search-normalize (state/enable-search-remove-accents?))))
 
 
-(defn block->index
-  "Convert a block to the index for searching"
+(defn- strict-block->index
+  "Convert a block to the index for searching.
+
+   Applies full text preprocessing to the content, including removing built-in properties"
   [{:block/keys [uuid page content format] :as block
   [{:block/keys [uuid page content format] :as block
     :or {format :markdown}}]
     :or {format :markdown}}]
   (when-not (> (count content) (max-len))
   (when-not (> (count content) (max-len))
@@ -32,6 +34,21 @@
          :page page
          :page page
          :content (sanitize content)}))))
          :content (sanitize content)}))))
 
 
+(defn- loose-block->index
+  "Convert a block to the index for searching
+
+   For speed, applies no preprocessing to the content"
+  [{:block/keys [uuid page content] :as block}]
+  (when-not (string/blank? content)
+    {:id (:db/id block)
+     :uuid (str uuid)
+     :page page
+     :content content}))
+
+(defonce block->index (if (util/electron?)
+                        strict-block->index
+                        loose-block->index))
+
 (defn page->index
 (defn page->index
   "Convert a page name to the index for searching (page content level)
   "Convert a page name to the index for searching (page content level)
    Generate index based on the DB content AT THE POINT OF TIME"
    Generate index based on the DB content AT THE POINT OF TIME"